2016-06-09 12:08:18 +02:00
|
|
|
module Carto
|
|
|
|
module Bano
|
|
|
|
# input : address
|
|
|
|
# output : Array List label address
|
|
|
|
class AddressRetriever
|
|
|
|
def initialize(address)
|
|
|
|
@address = address
|
|
|
|
end
|
|
|
|
|
|
|
|
def list
|
|
|
|
@list ||= convert_driver_result_to_full_address
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def driver
|
|
|
|
@driver ||= Carto::Bano::Driver.new @address, 5
|
|
|
|
end
|
|
|
|
|
|
|
|
def convert_driver_result_to_full_address
|
|
|
|
result = JSON.parse(driver.call)
|
|
|
|
|
|
|
|
if result['features'].size == 0
|
|
|
|
Rails.logger.error "unable to find location for address #{@address}"
|
|
|
|
return []
|
|
|
|
end
|
|
|
|
|
2018-01-15 21:33:29 +01:00
|
|
|
result['features'].map do |feature|
|
|
|
|
feature['properties']['label']
|
2016-06-09 12:08:18 +02:00
|
|
|
end
|
|
|
|
rescue TypeError, JSON::ParserError
|
|
|
|
[]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|