Change place lib repository
This commit is contained in:
parent
27cc62ea1e
commit
1a3e23c6ef
21 changed files with 0 additions and 0 deletions
30
app/lib/carto/bano/point_retriever.rb
Normal file
30
app/lib/carto/bano/point_retriever.rb
Normal file
|
@ -0,0 +1,30 @@
|
|||
module Carto
|
||||
module Bano
|
||||
# input : address
|
||||
# output : point RGeo::Cartesian::PointImpl
|
||||
class PointRetriever
|
||||
def initialize(address)
|
||||
@address = address
|
||||
end
|
||||
|
||||
def point
|
||||
@point ||= convert_driver_result_to_point
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def driver
|
||||
@driver ||= Carto::Bano::Driver.new @address
|
||||
end
|
||||
|
||||
def convert_driver_result_to_point
|
||||
result = JSON.parse(driver.call)
|
||||
if result['features'].size == 0
|
||||
Rails.logger.error "unable to find location for address #{@address}"
|
||||
return nil
|
||||
end
|
||||
RGeo::GeoJSON.decode(result['features'][0]['geometry'], json_parser: :json)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue