Class: Pumi::DataSource::Geocoder
- Inherits:
-
Object
- Object
- Pumi::DataSource::Geocoder
- Defined in:
- lib/pumi/data_source/geocoder.rb
Defined Under Namespace
Classes: AbstractGeocoder, CambodianCommunes, CambodianDistricts, CambodianProvinces, Result
Instance Attribute Summary collapse
-
#data_file ⇒ Object
readonly
Returns the value of attribute data_file.
-
#geocoder ⇒ Object
readonly
Returns the value of attribute geocoder.
Instance Method Summary collapse
-
#initialize(data_file:, geocoder:) ⇒ Geocoder
constructor
A new instance of Geocoder.
- #load_data!(output_dir: "data") ⇒ Object
Constructor Details
#initialize(data_file:, geocoder:) ⇒ Geocoder
Returns a new instance of Geocoder.
216 217 218 219 |
# File 'lib/pumi/data_source/geocoder.rb', line 216 def initialize(data_file:, geocoder:) @data_file = data_file @geocoder = geocoder end |
Instance Attribute Details
#data_file ⇒ Object (readonly)
Returns the value of attribute data_file.
214 215 216 |
# File 'lib/pumi/data_source/geocoder.rb', line 214 def data_file @data_file end |
#geocoder ⇒ Object (readonly)
Returns the value of attribute geocoder.
214 215 216 |
# File 'lib/pumi/data_source/geocoder.rb', line 214 def geocoder @geocoder end |
Instance Method Details
#load_data!(output_dir: "data") ⇒ Object
221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/pumi/data_source/geocoder.rb', line 221 def load_data!(output_dir: "data") data.each do |code, attributes| geocoded_result = geocoded_results.find { |r| r.code == code } next if geocoded_result.nil? attributes["geodata"] ||= {} attributes["geodata"]["lat"] = geocoded_result.lat attributes["geodata"]["long"] = geocoded_result.long attributes["geodata"]["bounding_box"] = geocoded_result.bounding_box end write_data!(output_dir) end |