Class: Pumi::DataSource::Geocoder

Inherits:
Object
  • Object
show all
Defined in:
lib/pumi/data_source/geocoder.rb

Defined Under Namespace

Classes: AbstractGeocoder, CambodianCommunes, CambodianDistricts, CambodianProvinces, Result

Instance Attribute Summary collapse

Instance Method Summary collapse

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_fileObject (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

#geocoderObject (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