Class: Geocoder::Result::Maxmind
- Defined in:
- lib/geocoder/results/maxmind.rb
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
-
.field_names ⇒ Object
Hash mapping service names to names of returned fields.
Instance Method Summary collapse
- #city ⇒ Object
- #coordinates ⇒ Object
-
#country ⇒ Object
not given by MaxMind.
- #country_code ⇒ Object
- #data_hash ⇒ Object
- #field_names ⇒ Object
- #method_missing(method, *args, &block) ⇒ Object
- #postal_code ⇒ Object
- #respond_to?(method) ⇒ Boolean
-
#service_name ⇒ Object
Name of the MaxMind service being used.
-
#state ⇒ Object
not given by MaxMind.
- #state_code ⇒ Object
Methods inherited from Base
#address, #initialize, #latitude, #longitude, #province, #province_code
Constructor Details
This class inherits a constructor from Geocoder::Result::Base
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
114 115 116 117 118 119 120 |
# 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 |
Class Method Details
.field_names ⇒ Object
Hash mapping service names to names of returned fields.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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 |
Instance Method Details
#city ⇒ Object
90 91 92 |
# File 'lib/geocoder/results/maxmind.rb', line 90 def city data_hash[:city_name] end |
#coordinates ⇒ Object
86 87 88 |
# File 'lib/geocoder/results/maxmind.rb', line 86 def coordinates [data_hash[:latitude].to_f, data_hash[:longitude].to_f] end |
#country ⇒ Object
not given by MaxMind
102 103 104 |
# 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 ⇒ Object
106 107 108 |
# File 'lib/geocoder/results/maxmind.rb', line 106 def country_code data_hash[:country_code] end |
#data_hash ⇒ Object
82 83 84 |
# File 'lib/geocoder/results/maxmind.rb', line 82 def data_hash @data_hash ||= Hash[*field_names.zip(@data).flatten] end |
#field_names ⇒ Object
78 79 80 |
# File 'lib/geocoder/results/maxmind.rb', line 78 def field_names self.class.field_names[service_name] end |
#postal_code ⇒ Object
110 111 112 |
# File 'lib/geocoder/results/maxmind.rb', line 110 def postal_code data_hash[:postal_code] end |
#respond_to?(method) ⇒ Boolean
122 123 124 125 126 127 128 |
# File 'lib/geocoder/results/maxmind.rb', line 122 def respond_to?(method) if field_names.include?(method) true else super end end |
#service_name ⇒ Object
Name of the MaxMind service being used.
71 72 73 74 75 76 |
# 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 ⇒ Object
not given by MaxMind
94 95 96 |
# 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 ⇒ Object
98 99 100 |
# File 'lib/geocoder/results/maxmind.rb', line 98 def state_code data_hash[:region_code] end |