Class: Ip2LocationRecord

Inherits:
Object
  • Object
show all
Defined in:
lib/ip2location_ruby/ip2location_record.rb

Class Method Summary collapse

Class Method Details

.init(database, ip_version) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/ip2location_ruby/ip2location_record.rb', line 2

def self.init(database, ip_version)
  cls = Class.new(BinData::Record)
  cls.class_eval {
    endian :little
    i2l_ip_data :ip_from, :ip_version => ip_version
    database.each do |col|
      if [:latitude, :longitude].include? col.first
        i2l_float_data col.first
      elsif col.first == :country
        i2l_string_data :country_short
        i2l_string_data :country_long, :country_long => true
      else
        i2l_string_data col.first
      end
    end
    
    i2l_ip_data :ip_to, :ip_version => ip_version
  }
  cls 
end