Refactor ApiAddresse::PointAdapter
This commit is contained in:
parent
145880555e
commit
d68aca545a
1 changed files with 5 additions and 12 deletions
|
@ -1,22 +1,15 @@
|
|||
class ApiAdresse::PointAdapter
|
||||
class ApiAdresse::PointAdapter < ApiAdresse::Adapter
|
||||
def initialize(address)
|
||||
@address = address
|
||||
super(address, 1, nil)
|
||||
end
|
||||
|
||||
def geocode
|
||||
@point ||= convert_api_result_to_point
|
||||
handle_result
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def convert_api_result_to_point
|
||||
result = JSON.parse(ApiAdresse::API.call(@address))
|
||||
|
||||
if result['features'].empty?
|
||||
Rails.logger.error "unable to find location for address #{@address}"
|
||||
return nil
|
||||
end
|
||||
|
||||
RGeo::GeoJSON.decode(result['features'][0]['geometry'], json_parser: :json)
|
||||
def process_features
|
||||
RGeo::GeoJSON.decode(features[0]['geometry'], json_parser: :json)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue