Class: AtlasEngine::AddressValidation::Suggestion

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
app/models/atlas_engine/address_validation/suggestion.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address1: nil, address2: nil, city: nil, zip: nil, province_code: nil, country_code: nil) ⇒ Suggestion

Returns a new instance of Suggestion.



40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 40

def initialize(address1: nil, address2: nil, city: nil, zip: nil, province_code: nil, country_code: nil)
  @address1 = address1
  @address2 = address2
  @city = city
  @zip = zip
  @province_code = province_code
  @original_country_code = country_code
  @country_code = country_code

  # generate_id uses the values of the attributes to calculate the UUID, so must be called after they're set
  @id = T.let(generate_id, String)
end

Instance Attribute Details

#address1Object

Returns the value of attribute address1.



13
14
15
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 13

def address1
  @address1
end

#address2Object

Returns the value of attribute address2.



16
17
18
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 16

def address2
  @address2
end

#cityObject

Returns the value of attribute city.



19
20
21
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 19

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



28
29
30
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 28

def country_code
  @country_code
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 10

def id
  @id
end

#province_codeObject



76
77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 76

def province_code
  return @province_code if @province_code.blank?

  # This hack is required since checkout-web is using province codes differently for Japan Vs Other countries
  # Japan province codes are expected as full ISO codes (JP-14)
  # while other countries are expected as 2 digit subdivision codes (e.g. ON)
  # we can remove this logic if the client can accept 2 digit subdivision codes / ISO codes as standard response
  province = Worldwide.region(code: @original_country_code)&.zone(code: @province_code)
  return @province_code unless province.province?

  province.legacy_code
end

#zipObject

Returns the value of attribute zip.



22
23
24
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 22

def zip
  @zip
end

Instance Method Details

#attributesObject



54
55
56
57
58
59
60
61
62
63
64
65
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 54

def attributes
  {
    id: id,
    address1: address1,
    address2: address2,
    city: city,
    zip: zip,
    province_code: province_code,
    province: province,
    country_code: country_code,
  }
end

#provinceObject



68
69
70
71
72
73
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 68

def province
  return if @original_country_code.nil? || @province_code.nil?

  province = Worldwide.region(code: @original_country_code)&.zone(code: @province_code)
  province.province? ? province.full_name : nil
end