Class: GeoIP::Record

Inherits:
FFI::Struct
  • Object
show all
Includes:
Tools
Defined in:
lib/ffi-geoip/record.rb

Constant Summary collapse

HASH_KEYS =
[
  :country_code,
  :country_code3,
  :country_name,
  :region,
  :city,
  :postal_code,
  :latitude,
  :longitude,
  :dma_code,
  :area_code
].freeze

Instance Method Summary collapse

Instance Method Details

#to_hObject



40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ffi-geoip/record.rb', line 40

def to_h
  hash = HASH_KEYS.each_with_object({}) do |key, memo|
    memo[key] = self[key] unless self[key].nil?
  end

  if self[:region]
    hash[:region_name] = FFIGeoIP.GeoIP_region_name_by_code(self[:country_code], self[:region])
  end

  fix_encoding(hash)
end