class Geocoder::Result::Opencagedata
Public Class Methods
response_attributes()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 87 def self.response_attributes %w[boundingbox license formatted stadium] end
Public Instance Methods
address()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 17 def address @data['formatted'] end
city()
click to toggle source
# 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()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 67 def coordinates [@data['geometry']['lat'].to_f, @data['geometry']['lng'].to_f] end
country()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 55 def country @data['components']['country'] end
country_code()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 59 def country_code @data['components']['country_code'] end
county()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 51 def county @data['components']['county'] end
house_number()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 13 def house_number @data['components']['house_number'] end
poi()
click to toggle source
# 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()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 47 def postal_code @data['components']['postcode'].to_s end
state()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 39 def state @data['components']['state'] end
state_code()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 43 def state_code @data['components']['state_code'] end
street()
click to toggle source
# 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()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 63 def suburb @data['components']['suburb'] end
time_zone()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 78 def time_zone # The OpenCage API documentation states that `annotations` is available # "when possible" https://geocoder.opencagedata.com/api#annotations @data .fetch('annotations', {}) .fetch('timezone', {}) .fetch('name', nil) end
viewport()
click to toggle source
# 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()
click to toggle source
# File lib/geocoder/results/opencagedata.rb, line 35 def village @data['components']['village'] end