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, #data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #province, #province_code
Class Method Details
.response_attributes ⇒ Object
53
54
55
|
# File 'lib/geocoder/results/geoip2.rb', line 53
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
25
26
27
28
|
# File 'lib/geocoder/results/geoip2.rb', line 25
def city
return '' unless @data['city']
@data['city']['names']['en']
end
|
#coordinates ⇒ Object
11
12
13
|
# File 'lib/geocoder/results/geoip2.rb', line 11
def coordinates
[latitude, longitude]
end
|
#country ⇒ Object
40
41
42
|
# File 'lib/geocoder/results/geoip2.rb', line 40
def country
@data['country']['names']['en']
end
|
#country_code ⇒ Object
44
45
46
|
# File 'lib/geocoder/results/geoip2.rb', line 44
def country_code
@data['country']['iso_code']
end
|
#latitude ⇒ Object
15
16
17
18
|
# File 'lib/geocoder/results/geoip2.rb', line 15
def latitude
return 0.0 unless @data['location']
@data['location']['latitude'].to_f
end
|
#longitude ⇒ Object
20
21
22
23
|
# File 'lib/geocoder/results/geoip2.rb', line 20
def longitude
return 0.0 unless @data['location']
@data['location']['longitude'].to_f
end
|
#postal_code ⇒ Object
48
49
50
51
|
# File 'lib/geocoder/results/geoip2.rb', line 48
def postal_code
return '' unless @data['postal']
@data['postal']['code']
end
|
#state ⇒ Object
30
31
32
33
|
# File 'lib/geocoder/results/geoip2.rb', line 30
def state
return '' unless @data['subdivisions']
@data['subdivisions'][0]['names']['en']
end
|
#state_code ⇒ Object
35
36
37
38
|
# File 'lib/geocoder/results/geoip2.rb', line 35
def state_code
return '' unless @data['subdivisions']
@data['subdivisions'][0]['iso_code']
end
|