Class: AtlasEngine::AddressValidation::Validators::FullAddress::PostalCodeMatcher

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from LogHelper

#log_error, #log_info, #log_warn

Constructor Details

#initialize(country_code, session_postal_code, candidate_postal_code = nil) ⇒ PostalCodeMatcher

Returns a new instance of PostalCodeMatcher.



21
22
23
24
25
# File 'app/models/atlas_engine/address_validation/validators/full_address/postal_code_matcher.rb', line 21

def initialize(country_code, session_postal_code, candidate_postal_code = nil)
  @country_code = country_code
  @session_postal_code = session_postal_code
  @candidate_postal_code = candidate_postal_code
end

Instance Attribute Details

#candidate_postal_codeObject (readonly)

Returns the value of attribute candidate_postal_code.



16
17
18
# File 'app/models/atlas_engine/address_validation/validators/full_address/postal_code_matcher.rb', line 16

def candidate_postal_code
  @candidate_postal_code
end

#country_codeObject (readonly)

Returns the value of attribute country_code.



16
17
18
# File 'app/models/atlas_engine/address_validation/validators/full_address/postal_code_matcher.rb', line 16

def country_code
  @country_code
end

#session_postal_codeObject (readonly)

Returns the value of attribute session_postal_code.



16
17
18
# File 'app/models/atlas_engine/address_validation/validators/full_address/postal_code_matcher.rb', line 16

def session_postal_code
  @session_postal_code
end

Instance Method Details

#truncateObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/atlas_engine/address_validation/validators/full_address/postal_code_matcher.rb', line 28

def truncate
  return unless candidate_postal_code
  return candidate_postal_code if candidate_postal_code.size <= session_postal_code.size
  return candidate_postal_code unless valid_partial_postal_code_length?

  truncated_postal_code = candidate_postal_code[partial_postal_code_range]

  log_info("Truncating candidate postal code", {
    session_postal_code: session_postal_code,
    original_postal_code: candidate_postal_code,
    truncated_postal_code: truncated_postal_code,
  })

  truncated_postal_code
end