Class: AtlasEngine::AddressValidation::Result

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

Constant Summary collapse

SORTED_VALIDATION_SCOPES =
T.let(
  [:country_code, :province_code, :zip, :city, :address1, :address2, :phone].freeze,
  T::Array[Symbol],
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_request_id: nil, origin: nil, fields: [], concerns: [], suggestions: [], validation_scope: [], errors: [], locale: "en", candidate: nil, matching_strategy: nil) ⇒ Result

Returns a new instance of Result.



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
# File 'app/models/atlas_engine/address_validation/result.rb', line 63

def initialize(
  client_request_id: nil,
  origin: nil,
  fields: [],
  concerns: [],
  suggestions: [],
  validation_scope: [],
  errors: [],
  locale: "en",
  candidate: nil,
  matching_strategy: nil
)
  @origin = origin
  @client_request_id = client_request_id
  @fields = fields
  @concerns = concerns
  @suggestions = suggestions
  @validation_scope = validation_scope
  @errors = errors
  @locale = locale
  @candidate = candidate
  @matching_strategy = matching_strategy

  # For now, this UUID isn't predicated on anything and is random.
  # There could be need in the future to help make this unique on all requests.
  # For now, what is important is that it one is simply generated and assigned.
  @id = T.let(generate_id, String)
end

Instance Attribute Details

#candidateObject

Returns the value of attribute candidate.



36
37
38
# File 'app/models/atlas_engine/address_validation/result.rb', line 36

def candidate
  @candidate
end

#client_request_idObject

Returns the value of attribute client_request_id.



15
16
17
# File 'app/models/atlas_engine/address_validation/result.rb', line 15

def client_request_id
  @client_request_id
end

#concernsObject

Returns the value of attribute concerns.



24
25
26
# File 'app/models/atlas_engine/address_validation/result.rb', line 24

def concerns
  @concerns
end

#errorsObject

Returns the value of attribute errors.



39
40
41
# File 'app/models/atlas_engine/address_validation/result.rb', line 39

def errors
  @errors
end

#fieldsObject

Returns the value of attribute fields.



21
22
23
# File 'app/models/atlas_engine/address_validation/result.rb', line 21

def fields
  @fields
end

#idObject (readonly)

Returns the value of attribute id.



42
43
44
# File 'app/models/atlas_engine/address_validation/result.rb', line 42

def id
  @id
end

#localeObject

Returns the value of attribute locale.



33
34
35
# File 'app/models/atlas_engine/address_validation/result.rb', line 33

def locale
  @locale
end

#matching_strategyObject (readonly)

Returns the value of attribute matching_strategy.



45
46
47
# File 'app/models/atlas_engine/address_validation/result.rb', line 45

def matching_strategy
  @matching_strategy
end

#originObject

Returns the value of attribute origin.



18
19
20
# File 'app/models/atlas_engine/address_validation/result.rb', line 18

def origin
  @origin
end

#suggestionsObject

Returns the value of attribute suggestions.



27
28
29
# File 'app/models/atlas_engine/address_validation/result.rb', line 27

def suggestions
  @suggestions
end

#validation_scopeObject

Returns the value of attribute validation_scope.



30
31
32
# File 'app/models/atlas_engine/address_validation/result.rb', line 30

def validation_scope
  @validation_scope
end

Instance Method Details

#add_concern(code:, type:, type_level:, suggestion_ids:, field_names:, message:) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/models/atlas_engine/address_validation/result.rb', line 114

def add_concern(code:, type:, type_level:, suggestion_ids:, field_names:, message:)
  new_concern = Concern.new(
    field_names: field_names,
    code: code,
    type: type,
    type_level: type_level,
    suggestion_ids: suggestion_ids,
    message: message,
  )
  concerns << new_concern
  new_concern
end

#add_suggestions(suggestions_to_add) ⇒ Object



130
131
132
# File 'app/models/atlas_engine/address_validation/result.rb', line 130

def add_suggestions(suggestions_to_add)
  suggestions_to_add.map { |suggestion| suggestions << suggestion }
end

#addressObject



140
141
142
143
144
# File 'app/models/atlas_engine/address_validation/result.rb', line 140

def address
  fields.each_with_object({}) do |field, hash|
    hash[field.name.to_sym] = field.value.to_s
  end
end

#attributesObject



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

def attributes
  {
    id: id,
    fields: fields.map(&:attributes),
    concerns: concerns.map(&:attributes),
    suggestions: suggestions.map(&:attributes),
    validation_scope: validation_scope,
    locale: locale,
  }
end

#completion_serviceObject



135
136
137
# File 'app/models/atlas_engine/address_validation/result.rb', line 135

def completion_service
  "AddressValidation"
end