class Pumi::DataSource::Geocoder::AbstractGeocoder
def build_result(code:, geocoder_result:)
def build_result(code:, geocoder_result:) Geocoder::Result.new( code:, lat: geocoder_result.lat, long: geocoder_result.long, bounding_box: geocoder_result.bounding_box ) end
def build_search_term(location)
def build_search_term(location) [location.full_name_km, location.name_km].map do |term| MISSPELLINGS.find { |m| m.correct_text == term }&.incorrect_text || term end end
def geocode(location)
def geocode(location) providers.each do |provider| Array(build_search_term(location)).each do |search_term| all_results = provider.search(search_term) geocoder_result = filter(location, all_results) return geocoder_result unless geocoder_result.nil? end end nil end
def geocode_all
def geocode_all locations.each_with_object([]).with_index do |(location, results), _index| next if !options[:regeocode] && !location.geodata.nil? geocoder_result = geocode(location) if geocoder_result.nil? ungeocoded_locations << location next end results << build_result(code: location.id, geocoder_result:) end end
def initialize(geocoder: ::Geocoder, providers: PROVIDERS.keys, **options)
def initialize(geocoder: ::Geocoder, providers: PROVIDERS.keys, **options) @options = options geocoder.configure( google: { api_key: ENV["GOOGLE_API_KEY"] } ) @providers = Array(providers).map do |name| PROVIDERS.fetch(name).new(geocoder:, name:) end end
def ungeocoded_locations
def ungeocoded_locations @ungeocoded_locations ||= [] end