Class: IpToAsn::AsEntry

Inherits:
Object
  • Object
show all
Defined in:
lib/iptoasn/asentry.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#countryObject

Returns the value of attribute country.



11
12
13
# File 'lib/iptoasn/asentry.rb', line 11

def country
  @country
end

#name_lengthObject

Returns the value of attribute name_length.



11
12
13
# File 'lib/iptoasn/asentry.rb', line 11

def name_length
  @name_length
end

#name_offsetObject

Returns the value of attribute name_offset.



11
12
13
# File 'lib/iptoasn/asentry.rb', line 11

def name_offset
  @name_offset
end

#numberObject

Returns the value of attribute number.



11
12
13
# File 'lib/iptoasn/asentry.rb', line 11

def number
  @number
end

#range_endObject

Returns the value of attribute range_end.



11
12
13
# File 'lib/iptoasn/asentry.rb', line 11

def range_end
  @range_end
end

#range_startObject

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

.sizeObject



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

#serializeObject



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