Class: Geocoder::Result::Geoip2
- Inherits:
-
Base
- Object
- Base
- Geocoder::Result::Geoip2
show all
- Defined in:
- lib/geocoder/results/geoip2.rb
Instance Attribute Summary
Attributes inherited from Base
#cache_hit
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #province, #province_code
Class Method Details
.response_attributes ⇒ Object
47
48
49
|
# File 'lib/geocoder/results/geoip2.rb', line 47
def self.response_attributes
%w[ip]
end
|
Instance Method Details
#address(format = :full) ⇒ Object
6
7
8
9
|
# File 'lib/geocoder/results/geoip2.rb', line 6
def address(format = :full)
s = state.to_s == '' ? '' : ", #{state_code}"
"#{city}#{s} #{postal_code}, #{country}".sub(/^[ ,]*/, '')
end
|
#city ⇒ Object
23
24
25
|
# File 'lib/geocoder/results/geoip2.rb', line 23
def city
data.fetch('city', {}).fetch('names', {}).fetch(locale, '')
end
|
#coordinates ⇒ Object
11
12
13
|
# File 'lib/geocoder/results/geoip2.rb', line 11
def coordinates
[latitude, longitude]
end
|
#country ⇒ Object
35
36
37
|
# File 'lib/geocoder/results/geoip2.rb', line 35
def country
data.fetch('country', {}).fetch('names', {}).fetch(locale, '')
end
|
#country_code ⇒ Object
39
40
41
|
# File 'lib/geocoder/results/geoip2.rb', line 39
def country_code
data.fetch('country', {}).fetch('iso_code', '')
end
|
#latitude ⇒ Object
15
16
17
|
# File 'lib/geocoder/results/geoip2.rb', line 15
def latitude
data.fetch('location', {}).fetch('latitude', 0.0)
end
|
#longitude ⇒ Object
19
20
21
|
# File 'lib/geocoder/results/geoip2.rb', line 19
def longitude
data.fetch('location', {}).fetch('longitude', 0.0)
end
|
#postal_code ⇒ Object
43
44
45
|
# File 'lib/geocoder/results/geoip2.rb', line 43
def postal_code
data.fetch('postal', {}).fetch('code', '')
end
|
#state ⇒ Object
27
28
29
|
# File 'lib/geocoder/results/geoip2.rb', line 27
def state
data.fetch('subdivisions', []).fetch(0, {}).fetch('names', {}).fetch(locale, '')
end
|
#state_code ⇒ Object
31
32
33
|
# File 'lib/geocoder/results/geoip2.rb', line 31
def state_code
data.fetch('subdivisions', []).fetch(0, {}).fetch('iso_code', '')
end
|