Class: Ronin::Support::Network::ASN::RecordSet
- Inherits:
-
Object
- Object
- Ronin::Support::Network::ASN::RecordSet
- Includes:
- Enumerable
- Defined in:
- lib/ronin/support/network/asn/record_set.rb
Overview
A sub-set of ASN records.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#records ⇒ Array<Record>, Enumerator::Lazy<Record>
readonly
The records in the record set.
Instance Method Summary collapse
-
#<<(record) ⇒ self
private
Adds a record to the record-set.
-
#countries ⇒ Set<String>
Retruns all country codes within the record set.
-
#country(country_code) ⇒ RecordSet
Selects all records with the matching country code.
-
#each {|record| ... } ⇒ Enumerator
Enumerates over each IP within all of the records.
-
#include?(ip) ⇒ Boolean
Determines if the IP belongs to any of the records.
-
#initialize(records = []) ⇒ RecordSet
constructor
private
Initializes the record-set.
-
#ip(ip) ⇒ Record?
Finds the ASN record for the given IP address.
-
#ipv4 ⇒ RecordSet
Selects only the records with IPv4 ranges.
-
#ipv6 ⇒ RecordSet
Selects only the records with IPv6 ranges.
-
#length ⇒ Integer
The number of records within the record-set.
-
#name(name) ⇒ RecordSet
Selects all records with the matching company name.
-
#names ⇒ Set<String>
Returns all company names within the record-set.
-
#number(number) ⇒ RecordSet
Selects all records with the matching AS number.
-
#numbers ⇒ Set<Integer>
Returns all AS numbers within the record set.
-
#ranges ⇒ Array<IPRange::Range>
Returns all IP ranges within the record set.
-
#to_a ⇒ Array<Range>
Converts the record-set to an Array of records.
Methods included from Enumerable
Constructor Details
#initialize(records = []) ⇒ RecordSet
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initializes the record-set.
45 46 47 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 45 def initialize(records=[]) @records = records end |
Instance Attribute Details
Instance Method Details
#<<(record) ⇒ self
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Adds a record to the record-set.
58 59 60 61 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 58 def <<(record) @records << record return self end |
#countries ⇒ Set<String>
Retruns all country codes within the record set.
107 108 109 110 111 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 107 def countries set = Set.new each { |record| set << record.country_code } set end |
#country(country_code) ⇒ RecordSet
Selects all records with the matching country code.
122 123 124 125 126 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 122 def country(country_code) RecordSet.new( lazy.select { |record| record.country_code == country_code } ) end |
#each {|record| ... } ⇒ Enumerator
Enumerates over each IP within all of the records.
72 73 74 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 72 def each(&block) @records.each(&block) end |
#include?(ip) ⇒ Boolean
Determines if the IP belongs to any of the records.
177 178 179 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 177 def include?(ip) !ip(ip).nil? end |
#ip(ip) ⇒ Record?
Finds the ASN record for the given IP address.
166 167 168 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 166 def ip(ip) find { |record| record.range.include?(ip) } end |
#ipv4 ⇒ RecordSet
Selects only the records with IPv4 ranges.
143 144 145 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 143 def ipv4 RecordSet.new(lazy.select(&:ipv4?)) end |
#ipv6 ⇒ RecordSet
Selects only the records with IPv6 ranges.
153 154 155 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 153 def ipv6 RecordSet.new(lazy.select(&:ipv6?)) end |
#length ⇒ Integer
The number of records within the record-set.
212 213 214 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 212 def length @records.length end |
#name(name) ⇒ RecordSet
Selects all records with the matching company name.
201 202 203 204 205 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 201 def name(name) RecordSet.new( lazy.select { |record| record.name == name } ) end |
#names ⇒ Set<String>
Returns all company names within the record-set.
186 187 188 189 190 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 186 def names set = Set.new each { |record| set << record.name } set end |
#number(number) ⇒ RecordSet
Selects all records with the matching AS number.
96 97 98 99 100 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 96 def number(number) RecordSet.new( lazy.select { |record| record.number == number } ) end |
#numbers ⇒ Set<Integer>
Returns all AS numbers within the record set.
81 82 83 84 85 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 81 def numbers set = Set.new each { |record| set << record.number } set end |
#ranges ⇒ Array<IPRange::Range>
Returns all IP ranges within the record set.
133 134 135 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 133 def ranges map(&:range) end |
#to_a ⇒ Array<Range>
Converts the record-set to an Array of records.
221 222 223 |
# File 'lib/ronin/support/network/asn/record_set.rb', line 221 def to_a @records.to_a end |