Class: AtlasEngine::AddressImporter::OpenAddress::DefaultMapper

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
FeatureHelper
Defined in:
app/models/atlas_engine/address_importer/open_address/default_mapper.rb

Instance Method Summary collapse

Methods included from FeatureHelper

#geometry, #housenumber_and_unit, #normalize_zip, #openaddress_source_id, #province_code_from_name, #province_code_from_zip, #province_from_code

Constructor Details

#initialize(country_code:, province_code: nil, locale: nil) ⇒ DefaultMapper

Returns a new instance of DefaultMapper.



11
12
13
14
15
# File 'app/models/atlas_engine/address_importer/open_address/default_mapper.rb', line 11

def initialize(country_code:, province_code: nil, locale: nil)
  @country_code = country_code
  @province_code = province_code
  @locale = locale
end

Instance Method Details

#map(feature) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'app/models/atlas_engine/address_importer/open_address/default_mapper.rb', line 18

def map(feature)
  region, city, street, number, unit, postcode = feature["properties"].values_at(
    "region",
    "city",
    "street",
    "number",
    "unit",
    "postcode",
  )
  {
    source_id: openaddress_source_id(feature),
    locale: @locale,
    country_code: @country_code,
    province_code: @province_code,
    region1: region,
    # Don't titleize. The sources have proper capitalization, and it's a problem for cities like
    # 's-Graveland, which would get titleized to "'S Graveland" which is wrong.
    city: [city],
    suburb: nil,
    zip: normalize_zip(postcode),
    street: street,
    building_and_unit_ranges: housenumber_and_unit(number, unit),
    latitude: geometry(feature)&.at(1),
    longitude: geometry(feature)&.at(0),
  }
end