Class: AtlasEngine::AddressImporter::OpenAddress::Transformer

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
app/models/atlas_engine/address_importer/open_address/transformer.rb

Instance Method Summary collapse

Constructor Details

#initialize(country_import:, province_code: nil, locale: nil) ⇒ Transformer

Returns a new instance of Transformer.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/atlas_engine/address_importer/open_address/transformer.rb', line 11

def initialize(country_import:, province_code: nil, locale: nil)
  @country_code = country_import.country_code
  @locale = locale
  @province_code = province_code
  @mapper = CountryProfile.for(@country_code).ingestion.post_address_mapper("open_address").new(
    country_code: @country_code, province_code: @province_code, locale: @locale,
  )
  @corrector = AddressImporter::Corrections::Corrector.new(country_code: @country_code, source: "open_address")
  @validator = AddressImporter::Validation::Wrapper.new(
    country_import: country_import,
    log_invalid_records: false,
  )
end

Instance Method Details

#transform(feature) ⇒ Object



29
30
31
32
33
34
35
36
# File 'app/models/atlas_engine/address_importer/open_address/transformer.rb', line 29

def transform(feature)
  address_hash = @mapper.map(feature)

  @corrector.apply(address_hash)
  return if address_hash.blank?

  address_hash if @validator.valid?(address_hash)
end