Class: Pumi::DataSource::Geocoder::AbstractGeocoder
- Inherits:
-
Object
- Object
- Pumi::DataSource::Geocoder::AbstractGeocoder
- Defined in:
- lib/pumi/data_source/geocoder.rb
Direct Known Subclasses
Defined Under Namespace
Classes: AbstractProvider, Google, Misspelling, Nominatim, Result
Constant Summary collapse
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#providers ⇒ Object
readonly
Returns the value of attribute providers.
Instance Method Summary collapse
- #geocode_all ⇒ Object
-
#initialize(geocoder: ::Geocoder, providers: PROVIDERS.keys, **options) ⇒ AbstractGeocoder
constructor
A new instance of AbstractGeocoder.
Constructor Details
#initialize(geocoder: ::Geocoder, providers: PROVIDERS.keys, **options) ⇒ AbstractGeocoder
Returns a new instance of AbstractGeocoder.
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/pumi/data_source/geocoder.rb', line 95 def initialize(geocoder: ::Geocoder, providers: PROVIDERS.keys, **) @options = geocoder.configure( google: { api_key: ENV["GOOGLE_API_KEY"] } ) @providers = Array(providers).map do |name| PROVIDERS.fetch(name).new(geocoder:, name:) end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
93 94 95 |
# File 'lib/pumi/data_source/geocoder.rb', line 93 def @options end |
#providers ⇒ Object (readonly)
Returns the value of attribute providers.
93 94 95 |
# File 'lib/pumi/data_source/geocoder.rb', line 93 def providers @providers end |
Instance Method Details
#geocode_all ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/pumi/data_source/geocoder.rb', line 109 def geocode_all locations.each_with_object([]).with_index do |(location, results), _index| next if ![: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 |