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, street_name: nil, street_number: nil, address2: nil, line2: nil, neighborhood: nil, city: nil, zip: nil, province_code: nil, country_code: nil) ⇒ Suggestion

Returns a new instance of Suggestion.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 56

def initialize(address1: nil, street_name: nil, street_number: nil, address2: nil, line2: nil, neighborhood: nil,
  city: nil, zip: nil, province_code: nil, country_code: nil)
  @address1 = address1
  @street_name = street_name
  @street_number = street_number
  @address2 = address2
  @line2 = line2
  @neighborhood = neighborhood
  @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.



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

def address2
  @address2
end

#cityObject

Returns the value of attribute city.



31
32
33
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 31

def city
  @city
end

#country_codeObject

Returns the value of attribute country_code.



40
41
42
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 40

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

#line2Object

Returns the value of attribute line2.



25
26
27
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 25

def line2
  @line2
end

#neighborhoodObject

Returns the value of attribute neighborhood.



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

def neighborhood
  @neighborhood
end

#province_codeObject



101
102
103
104
105
106
107
108
109
110
111
112
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 101

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

#street_nameObject

Returns the value of attribute street_name.



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

def street_name
  @street_name
end

#street_numberObject

Returns the value of attribute street_number.



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

def street_number
  @street_number
end

#zipObject

Returns the value of attribute zip.



34
35
36
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 34

def zip
  @zip
end

Instance Method Details

#attributesObject



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

def attributes
  {
    id: id,
    address1: address1,
    street_name: street_name,
    street_number: street_number,
    address2: address2,
    line2: line2,
    neighborhood: neighborhood,
    city: city,
    zip: zip,
    province_code: province_code,
    province: province,
    country_code: country_code,
  }
end

#provinceObject



93
94
95
96
97
98
# File 'app/models/atlas_engine/address_validation/suggestion.rb', line 93

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