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
#address, #initialize, #latitude, #longitude, #province, #province_code
Class Method Details
.response_attributes ⇒ Object
43
44
45
|
# File 'lib/geocoder/results/geoip2.rb', line 43
def self.response_attributes
%w[ip]
end
|
Instance Method Details
#city ⇒ Object
13
14
15
16
17
|
# File 'lib/geocoder/results/geoip2.rb', line 13
def city
fetch_name(
data.fetch('city', {}).fetch('names', {})
)
end
|
#coordinates ⇒ Object
7
8
9
10
11
|
# File 'lib/geocoder/results/geoip2.rb', line 7
def coordinates
%w[latitude longitude].map do |l|
data.fetch('location', {}).fetch(l, 0.0)
end
end
|
#country ⇒ Object
29
30
31
32
33
|
# File 'lib/geocoder/results/geoip2.rb', line 29
def country
fetch_name(
data.fetch('country', {}).fetch('names', {})
)
end
|
#country_code ⇒ Object
35
36
37
|
# File 'lib/geocoder/results/geoip2.rb', line 35
def country_code
data.fetch('country', {}).fetch('iso_code', '')
end
|
#data ⇒ Object
61
62
63
|
# File 'lib/geocoder/results/geoip2.rb', line 61
def data
@data.to_hash
end
|
#language ⇒ Object
57
58
59
|
# File 'lib/geocoder/results/geoip2.rb', line 57
def language
@language ||= default_language
end
|
#language=(l) ⇒ Object
53
54
55
|
# File 'lib/geocoder/results/geoip2.rb', line 53
def language=(l)
@language = l.to_s
end
|
#postal_code ⇒ Object
39
40
41
|
# File 'lib/geocoder/results/geoip2.rb', line 39
def postal_code
data.fetch('postal', {}).fetch('code', '')
end
|
#state ⇒ Object
19
20
21
22
23
|
# File 'lib/geocoder/results/geoip2.rb', line 19
def state
fetch_name(
data.fetch('subdivisions', []).fetch(0, {}).fetch('names', {})
)
end
|
#state_code ⇒ Object
25
26
27
|
# File 'lib/geocoder/results/geoip2.rb', line 25
def state_code
data.fetch('subdivisions', []).fetch(0, {}).fetch('iso_code', '')
end
|