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",
    street_name: "street_name",
    street_number: "street_number",
    neighborhood: "neighborhood",
    line2: "line2",
    phone: "phone",
  },
  T::Hash[Symbol, String],
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Validator.



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
90
91
92
93
94
95
96
97
98
99
100
101
# File 'app/models/atlas_engine/address_validation/validator.rb', line 63

def initialize(
  address:,
  matching_strategy:,
  locale: "en",
  context: {},
  message_format: MessageFormat::Instructional
)
  @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)
  @message_format = T.let(message_format, MessageFormat)

  matching_strategy_name = matching_strategy.serialize

  @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,
  )
  pipeline_builder = PredicatePipelineBuilder.new(matching_strategy_name:, address:, result:, message_format:)

  @pipeline = T.let(
    pipeline_builder.pipeline,
    T::Array[AtlasEngine::AddressValidation::PredicatePipeline::PredicateConfig],
  )
  @unsupported_fields = T.let(pipeline_builder.unsupported_fields, T::Array[Symbol])
  @full_address_validator = T.let(pipeline_builder.full_address_validator, 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

#message_formatObject (readonly)

Returns the value of attribute message_format.



35
36
37
# File 'app/models/atlas_engine/address_validation/validator.rb', line 35

def message_format
  @message_format
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

#unsupported_fieldsObject (readonly)

Returns the value of attribute unsupported_fields.



32
33
34
# File 'app/models/atlas_engine/address_validation/validator.rb', line 32

def unsupported_fields
  @unsupported_fields
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



115
116
117
118
119
# File 'app/models/atlas_engine/address_validation/validator.rb', line 115

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

#runObject



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

def run
  build_fields

  populate_result(execute_pipeline)

  validate_full_address

  result
end