Class: AtlasEngine::AddressValidation::Es::DataMappers::DefaultDataMapper

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
LogHelper
Defined in:
app/models/atlas_engine/address_validation/es/data_mappers/default_data_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogHelper

#log_error, #log_info, #log_warn

Constructor Details

#initialize(post_address:, country_profile:, locale: "") ⇒ DefaultDataMapper

Returns a new instance of DefaultDataMapper.



25
26
27
28
29
# File 'app/models/atlas_engine/address_validation/es/data_mappers/default_data_mapper.rb', line 25

def initialize(post_address:, country_profile:, locale: "")
  @post_address = post_address
  @country_profile = country_profile
  @locale = T.let((locale.empty? ? post_address[:locale] : locale), String)
end

Instance Attribute Details

#localeObject (readonly)

Returns the value of attribute locale.



16
17
18
# File 'app/models/atlas_engine/address_validation/es/data_mappers/default_data_mapper.rb', line 16

def locale
  @locale
end

#post_addressObject (readonly)

Returns the value of attribute post_address.



13
14
15
# File 'app/models/atlas_engine/address_validation/es/data_mappers/default_data_mapper.rb', line 13

def post_address
  @post_address
end

Instance Method Details

#map_dataObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/models/atlas_engine/address_validation/es/data_mappers/default_data_mapper.rb', line 34

def map_data
  {}.tap do |data|
    data.update(
      post_address
        .slice(:id, :locale, :country_code, :province_code, :region1, :region2, :region3, :region4)
        .deep_symbolize_keys,
    )
    data[:city] = post_address[:city].first
    data[:city_aliases] = city_aliases(post_address[:city])
    data[:suburb] = post_address[:suburb]
    data[:zip] = Worldwide::Zip.normalize(
      country_code: post_address[:country_code],
      zip: post_address[:zip],
    )
    data[:street] = post_address[:street]
    data[:street_stripped] = street_stripped(post_address[:street])
    data[:street_decompounded] = nil
    data[:building_and_unit_ranges] = JSON.generate(post_address[:building_and_unit_ranges])
    data[:approx_building_ranges] = approx_building_ranges(post_address[:building_and_unit_ranges]&.keys)
    data.update(
      post_address.slice(:building_name, :latitude, :longitude).deep_symbolize_keys,
    )
    data[:location] = {
      lat: post_address[:latitude],
      lon: post_address[:longitude],
    }
  end
end