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
- #address(format = :full) ⇒ Object
- #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
#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
120 121 122 123 124 125 126 |
# File 'lib/geocoder/results/maxmind.rb', line 120 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
#address(format = :full) ⇒ Object
91 92 93 94 |
# File 'lib/geocoder/results/maxmind.rb', line 91 def address(format = :full) s = state_code.to_s == "" ? "" : ", #{state_code}" "#{city}#{s} #{postal_code}, #{country_code}".sub(/^[ ,]*/, "") end |
#city ⇒ Object
96 97 98 |
# File 'lib/geocoder/results/maxmind.rb', line 96 def city data_hash[:city_name] end |
#coordinates ⇒ Object
87 88 89 |
# File 'lib/geocoder/results/maxmind.rb', line 87 def coordinates [data_hash[:latitude].to_f, data_hash[:longitude].to_f] end |
#country ⇒ Object
not given by MaxMind
108 109 110 |
# File 'lib/geocoder/results/maxmind.rb', line 108 def country #not given by MaxMind data_hash[:country_name] || data_hash[:country_code] end |
#country_code ⇒ Object
112 113 114 |
# File 'lib/geocoder/results/maxmind.rb', line 112 def country_code data_hash[:country_code] end |
#data_hash ⇒ Object
83 84 85 |
# File 'lib/geocoder/results/maxmind.rb', line 83 def data_hash @data_hash ||= Hash[*field_names.zip(@data).flatten] end |
#field_names ⇒ Object
79 80 81 |
# File 'lib/geocoder/results/maxmind.rb', line 79 def field_names self.class.field_names[service_name] end |
#postal_code ⇒ Object
116 117 118 |
# File 'lib/geocoder/results/maxmind.rb', line 116 def postal_code data_hash[:postal_code] end |
#respond_to?(method) ⇒ Boolean
128 129 130 131 132 133 134 |
# File 'lib/geocoder/results/maxmind.rb', line 128 def respond_to?(method) if field_names.include?(method) true else super end end |
#service_name ⇒ Object
Name of the MaxMind service being used. Inferred from format of @data.
72 73 74 75 76 77 |
# File 'lib/geocoder/results/maxmind.rb', line 72 def service_name self.class.field_names.to_a.each do |n,f| return n if f.size == @data.size end nil end |
#state ⇒ Object
not given by MaxMind
100 101 102 |
# File 'lib/geocoder/results/maxmind.rb', line 100 def state # not given by MaxMind data_hash[:region_name] || data_hash[:region_code] end |
#state_code ⇒ Object
104 105 106 |
# File 'lib/geocoder/results/maxmind.rb', line 104 def state_code data_hash[:region_code] end |