Class: IpToAsn::AsEntry
- Inherits:
-
Object
- Object
- IpToAsn::AsEntry
- Defined in:
- lib/iptoasn/asentry.rb
Instance Attribute Summary collapse
-
#country ⇒ Object
Returns the value of attribute country.
-
#name_length ⇒ Object
Returns the value of attribute name_length.
-
#name_offset ⇒ Object
Returns the value of attribute name_offset.
-
#number ⇒ Object
Returns the value of attribute number.
-
#range_end ⇒ Object
Returns the value of attribute range_end.
-
#range_start ⇒ Object
Returns the value of attribute range_start.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(range_start, range_end, number, country, name_offset, name_length) ⇒ AsEntry
constructor
rubocop:disable Metrics/ParameterLists.
- #serialize ⇒ Object
Constructor Details
#initialize(range_start, range_end, number, country, name_offset, name_length) ⇒ AsEntry
rubocop:disable Metrics/ParameterLists
13 14 15 16 17 18 19 20 |
# File 'lib/iptoasn/asentry.rb', line 13 def initialize(range_start, range_end, number, country, name_offset, name_length) # rubocop:disable Metrics/ParameterLists @range_start = ip_to_int(range_start) @range_end = ip_to_int(range_end) @number = number @country = country @name_offset = name_offset @name_length = name_length end |
Instance Attribute Details
#country ⇒ Object
Returns the value of attribute country.
11 12 13 |
# File 'lib/iptoasn/asentry.rb', line 11 def country @country end |
#name_length ⇒ Object
Returns the value of attribute name_length.
11 12 13 |
# File 'lib/iptoasn/asentry.rb', line 11 def name_length @name_length end |
#name_offset ⇒ Object
Returns the value of attribute name_offset.
11 12 13 |
# File 'lib/iptoasn/asentry.rb', line 11 def name_offset @name_offset end |
#number ⇒ Object
Returns the value of attribute number.
11 12 13 |
# File 'lib/iptoasn/asentry.rb', line 11 def number @number end |
#range_end ⇒ Object
Returns the value of attribute range_end.
11 12 13 |
# File 'lib/iptoasn/asentry.rb', line 11 def range_end @range_end end |
#range_start ⇒ Object
Returns the value of attribute range_start.
11 12 13 |
# File 'lib/iptoasn/asentry.rb', line 11 def range_start @range_start end |
Class Method Details
.deserialize(binary_data) ⇒ Object
26 27 28 29 |
# File 'lib/iptoasn/asentry.rb', line 26 def self.deserialize(binary_data) range_start, range_end, number, country, name_offset, name_length = binary_data.unpack('L L L C L C') new(int_to_ip(range_start), int_to_ip(range_end), number, country, name_offset, name_length) end |
.int_to_ip(int) ⇒ Object
35 36 37 |
# File 'lib/iptoasn/asentry.rb', line 35 def self.int_to_ip(int) [24, 16, 8, 0].map { |b| (int >> b) & 0xFF }.join('.') end |
.size ⇒ Object
31 32 33 |
# File 'lib/iptoasn/asentry.rb', line 31 def self.size 18 # L + L + L + C + L + C = 18 bytes end |
Instance Method Details
#serialize ⇒ Object
22 23 24 |
# File 'lib/iptoasn/asentry.rb', line 22 def serialize [@range_start, @range_end, @number, @country, @name_offset, @name_length].pack('L L L C L C') end |