class Geocoder::Result::Opencagedata
def self.response_attributes
def self.response_attributes %w[boundingbox license formatted stadium] end
def address
def address @data['formatted'] end
def city
def city %w[city town village hamlet].each do |key| return @data['components'][key] if @data['components'].key?(key) end return nil end
def coordinates
def coordinates [@data['geometry']['lat'].to_f, @data['geometry']['lng'].to_f] end
def country
def country @data['components']['country'] end
def country_code
def country_code @data['components']['country_code'] end
def county
def county @data['components']['county'] end
def house_number
def house_number @data['components']['house_number'] end
def poi
def poi %w[stadium bus_stop tram_stop].each do |key| return @data['components'][key] if @data['components'].key?(key) end return nil end
def postal_code
def postal_code @data['components']['postcode'].to_s end
def state
def state @data['components']['state'] end
def state_code
def state_code @data['components']['state_code'] end
def street
def street %w[road pedestrian highway].each do |key| return @data['components'][key] if @data['components'].key?(key) end return nil end
def suburb
def suburb @data['components']['suburb'] end
def time_zone
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
def viewport
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
def village
def village @data['components']['village'] end