class Geocoder::Result::Maxmind
Public Class Methods
field_names()
click to toggle source
Hash
mapping service names to names of returned fields.
# File lib/geocoder/results/maxmind.rb, line 9 def self.field_names { :country => [ :country_code, :error ], :city => [ :country_code, :region_code, :city_name, :latitude, :longitude, :error ], :city_isp_org => [ :country_code, :region_code, :city_name, :postal_code, :latitude, :longitude, :metro_code, :area_code, :isp_name, :organization_name, :error ], :omni => [ :country_code, :country_name, :region_code, :region_name, :city_name, :latitude, :longitude, :metro_code, :area_code, :time_zone, :continent_code, :postal_code, :isp_name, :organization_name, :domain, :as_number, :netspeed, :user_type, :accuracy_radius, :country_confidence_factor, :city_confidence_factor, :region_confidence_factor, :postal_confidence_factor, :error ] } end
Public Instance Methods
city()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 90 def city data_hash[:city_name] end
coordinates()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 86 def coordinates [data_hash[:latitude].to_f, data_hash[:longitude].to_f] end
country()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 102 def country #not given by MaxMind data_hash[:country_name] || data_hash[:country_code] end
country_code()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 106 def country_code data_hash[:country_code] end
data_hash()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 82 def data_hash @data_hash ||= Hash[*field_names.zip(@data).flatten] end
field_names()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 78 def field_names self.class.field_names[service_name] end
method_missing(method, *args, &block)
click to toggle source
Calls superclass method
# File lib/geocoder/results/maxmind.rb, line 114 def method_missing(method, *args, &block) if field_names.include?(method) data_hash[method] else super end end
postal_code()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 110 def postal_code data_hash[:postal_code] end
respond_to?(method)
click to toggle source
Calls superclass method
# File lib/geocoder/results/maxmind.rb, line 122 def respond_to?(method) if field_names.include?(method) true else super end end
service_name()
click to toggle source
Name of the MaxMind service being used.
# File lib/geocoder/results/maxmind.rb, line 71 def service_name # it would be much better to infer this from the length of the @data # array, but MaxMind seems to send inconsistent and wide-ranging response # lengths (see https://github.com/alexreisner/geocoder/issues/396) Geocoder.config.maxmind[:service] end
state()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 94 def state # not given by MaxMind data_hash[:region_name] || data_hash[:region_code] end
state_code()
click to toggle source
# File lib/geocoder/results/maxmind.rb, line 98 def state_code data_hash[:region_code] end