Class: Geocoder::Result::Opencagedata
- Inherits:
-
Base
- Object
- Base
- Geocoder::Result::Opencagedata
show all
- Defined in:
- lib/geocoder/results/opencagedata.rb
Instance Attribute Summary
Attributes inherited from Base
#cache_hit, #data
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #latitude, #longitude, #province, #province_code
Class Method Details
.response_attributes ⇒ Object
87
88
89
90
|
# File 'lib/geocoder/results/opencagedata.rb', line 87
def self.response_attributes
%w[boundingbox license
formatted stadium]
end
|
Instance Method Details
#address ⇒ Object
17
18
19
|
# File 'lib/geocoder/results/opencagedata.rb', line 17
def address
@data['formatted']
end
|
#city ⇒ Object
28
29
30
31
32
33
|
# File 'lib/geocoder/results/opencagedata.rb', line 28
def city
%w[city town village hamlet].each do |key|
return @data['components'][key] if @data['components'].key?(key)
end
return nil
end
|
#coordinates ⇒ Object
67
68
69
|
# File 'lib/geocoder/results/opencagedata.rb', line 67
def coordinates
[@data['geometry']['lat'].to_f, @data['geometry']['lng'].to_f]
end
|
#country ⇒ Object
55
56
57
|
# File 'lib/geocoder/results/opencagedata.rb', line 55
def country
@data['components']['country']
end
|
#country_code ⇒ Object
59
60
61
|
# File 'lib/geocoder/results/opencagedata.rb', line 59
def country_code
@data['components']['country_code']
end
|
#county ⇒ Object
51
52
53
|
# File 'lib/geocoder/results/opencagedata.rb', line 51
def county
@data['components']['county']
end
|
#house_number ⇒ Object
13
14
15
|
# File 'lib/geocoder/results/opencagedata.rb', line 13
def house_number
@data['components']['house_number']
end
|
#poi ⇒ Object
6
7
8
9
10
11
|
# File 'lib/geocoder/results/opencagedata.rb', line 6
def poi
%w[stadium bus_stop tram_stop].each do |key|
return @data['components'][key] if @data['components'].key?(key)
end
return nil
end
|
#postal_code ⇒ Object
47
48
49
|
# File 'lib/geocoder/results/opencagedata.rb', line 47
def postal_code
@data['components']['postcode'].to_s
end
|
#state ⇒ Object
39
40
41
|
# File 'lib/geocoder/results/opencagedata.rb', line 39
def state
@data['components']['state']
end
|
#state_code ⇒ Object
43
44
45
|
# File 'lib/geocoder/results/opencagedata.rb', line 43
def state_code
@data['components']['state_code']
end
|
#street ⇒ Object
21
22
23
24
25
26
|
# File 'lib/geocoder/results/opencagedata.rb', line 21
def street
%w[road pedestrian highway].each do |key|
return @data['components'][key] if @data['components'].key?(key)
end
return nil
end
|
#suburb ⇒ Object
63
64
65
|
# File 'lib/geocoder/results/opencagedata.rb', line 63
def suburb
@data['components']['suburb']
end
|
#time_zone ⇒ Object
78
79
80
81
82
83
84
85
|
# File 'lib/geocoder/results/opencagedata.rb', line 78
def time_zone
@data
.fetch('annotations', {})
.fetch('timezone', {})
.fetch('name', nil)
end
|
#viewport ⇒ Object
71
72
73
74
75
76
|
# File 'lib/geocoder/results/opencagedata.rb', line 71
def viewport
bounds = @data['bounds'] || fail
south, west = %w(lat lng).map { |i| bounds['southwest'][i] }
north, east = %w(lat lng).map { |i| bounds['northeast'][i] }
[south, west, north, east]
end
|
#village ⇒ Object
35
36
37
|
# File 'lib/geocoder/results/opencagedata.rb', line 35
def village
@data['components']['village']
end
|