Class: AtlasEngine::AddressValidation::Validator

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

Constant Summary collapse

FIELD_MAP =
T.let(
  {
    country: "country_code",
    province: "province_code",
    zip: "zip",
    city: "city",
    address1: "address1",
    address2: "address2",
    phone: "phone",
  },
  T::Hash[Symbol, String],
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(address:, matching_strategy:, locale: "en", context: {}) ⇒ Validator

Returns a new instance of Validator.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# File 'app/models/atlas_engine/address_validation/validator.rb', line 52

def initialize(
  address:,
  matching_strategy:,
  locale: "en",
  context: {}
)
  @address = T.let(address, AbstractAddress)
  @address1 = T.let(address.address1, T.nilable(String))
  @address2 = T.let(address.address2, T.nilable(String))
  @city = T.let(address.city, T.nilable(String))
  @province_code = T.let(address.province_code, T.nilable(String))
  @phone = T.let(address.phone, T.nilable(String))
  @zip = T.let(address.zip, T.nilable(String))
  @country_code = T.let(address.country_code, T.nilable(String))
  @context = T.let(context, T::Hash[T.untyped, T.untyped])
  @matching_strategy = T.let(matching_strategy, Strategies)

  matching_strategy_name = matching_strategy.serialize
  @predicate_pipeline = T.let(PredicatePipeline.find(matching_strategy_name), PredicatePipeline)

  @result = T.let(
    Result.new(
      client_request_id: context.dig(:client_request_id),
      origin: context.dig(:origin),
      locale: locale,
      matching_strategy: matching_strategy_name,
    ),
    Result,
  )

  @full_address_validator = T.let(
    @predicate_pipeline.full_address_validator&.new(
      address: @address,
      result: @result,
    ),
    T.nilable(FullAddressValidatorBase),
  )
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



23
24
25
# File 'app/models/atlas_engine/address_validation/validator.rb', line 23

def address
  @address
end

#address1Object (readonly)

Returns the value of attribute address1.



11
12
13
# File 'app/models/atlas_engine/address_validation/validator.rb', line 11

def address1
  @address1
end

#address2Object (readonly)

Returns the value of attribute address2.



11
12
13
# File 'app/models/atlas_engine/address_validation/validator.rb', line 11

def address2
  @address2
end

#cityObject (readonly)

Returns the value of attribute city.



11
12
13
# File 'app/models/atlas_engine/address_validation/validator.rb', line 11

def city
  @city
end

#contextObject (readonly)

Returns the value of attribute context.



26
27
28
# File 'app/models/atlas_engine/address_validation/validator.rb', line 26

def context
  @context
end

#country_codeObject (readonly)

Returns the value of attribute country_code.



11
12
13
# File 'app/models/atlas_engine/address_validation/validator.rb', line 11

def country_code
  @country_code
end

#full_address_validatorObject (readonly)

Returns the value of attribute full_address_validator.



29
30
31
# File 'app/models/atlas_engine/address_validation/validator.rb', line 29

def full_address_validator
  @full_address_validator
end

#phoneObject (readonly)

Returns the value of attribute phone.



11
12
13
# File 'app/models/atlas_engine/address_validation/validator.rb', line 11

def phone
  @phone
end

#province_codeObject (readonly)

Returns the value of attribute province_code.



11
12
13
# File 'app/models/atlas_engine/address_validation/validator.rb', line 11

def province_code
  @province_code
end

#resultObject (readonly)

Returns the value of attribute result.



20
21
22
# File 'app/models/atlas_engine/address_validation/validator.rb', line 20

def result
  @result
end

#zipObject (readonly)

Returns the value of attribute zip.



11
12
13
# File 'app/models/atlas_engine/address_validation/validator.rb', line 11

def zip
  @zip
end

Instance Method Details

#build_fieldsObject



103
104
105
106
107
# File 'app/models/atlas_engine/address_validation/validator.rb', line 103

def build_fields
  result.fields = address.keys.map do |field|
    Field.new(name: field, value: address[field])
  end
end

#runObject



92
93
94
95
96
97
98
99
100
# File 'app/models/atlas_engine/address_validation/validator.rb', line 92

def run
  build_fields

  populate_result(execute_pipeline)

  validate_full_address

  result
end