Class: AtlasEngine::AddressValidation::Validators::FullAddress::ConcernBuilder

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(unmatched_component:, matched_components:, address:, suggestion_ids:, message_format:, unmatched_field: nil) ⇒ ConcernBuilder

Returns a new instance of ConcernBuilder.



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 91

def initialize(
  unmatched_component:,
  matched_components:,
  address:,
  suggestion_ids:,
  message_format:,
  unmatched_field: nil
)
  @unmatched_component = unmatched_component
  @unmatched_field = unmatched_field
  @matched_components = matched_components
  @address = address
  @suggestion_ids = suggestion_ids
  @message_format = message_format
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.



11
12
13
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 11

def address
  @address
end

#matched_componentsObject (readonly)

Returns the value of attribute matched_components.



11
12
13
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 11

def matched_components
  @matched_components
end

#message_formatObject (readonly)

Returns the value of attribute message_format.



11
12
13
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 11

def message_format
  @message_format
end

#suggestion_idsObject (readonly)

Returns the value of attribute suggestion_ids.



11
12
13
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 11

def suggestion_ids
  @suggestion_ids
end

#unmatched_componentObject (readonly)

Returns the value of attribute unmatched_component.



11
12
13
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 11

def unmatched_component
  @unmatched_component
end

#unmatched_fieldObject (readonly)

Returns the value of attribute unmatched_field.



11
12
13
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 11

def unmatched_field
  @unmatched_field
end

Class Method Details

.should_suggest?(address, unmatched_component_keys) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 27

def should_suggest?(address, unmatched_component_keys)
  return false if too_many_unmatched_components?(address, unmatched_component_keys)

  return false if province_and_city_xor_zip?(unmatched_component_keys) && !valid_zip_for_province?(address)

  true
end

.too_many_unmatched_components?(address, unmatched_component_keys) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 41

def too_many_unmatched_components?(address, unmatched_component_keys)
  unmatched_component_keys.size > unmatched_components_suggestion_threshold(address)
end

.valid_zip_for_province?(address) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 46

def valid_zip_for_province?(address)
  !country_has_zip_codes(address) || province_postal_code_valid?(address)
end

Instance Method Details

#buildObject



108
109
110
111
112
113
114
115
116
117
# File 'app/models/atlas_engine/address_validation/validators/full_address/concern_builder.rb', line 108

def build
  case unmatched_component
  when :zip
    build_zip_concern
  when :province_code
    build_province_concern
  else
    build_default_concern
  end
end