Class: AtlasEngine::AddressValidation::Validators::Predicates::Country::ValidForZip

Inherits:
Predicate
  • Object
show all
Defined in:
app/models/atlas_engine/address_validation/validators/predicates/country/valid_for_zip.rb

Instance Attribute Summary

Attributes inherited from Predicate

#address, #cache, #field, #message_format

Instance Method Summary collapse

Methods inherited from Predicate

#initialize

Constructor Details

This class inherits a constructor from AtlasEngine::AddressValidation::Validators::Predicates::Predicate

Instance Method Details

#evaluateObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/models/atlas_engine/address_validation/validators/predicates/country/valid_for_zip.rb', line 11

def evaluate
  return unless @cache.country.country?
  return if @address.zip.blank?

  suggested_country = Worldwide::Zip.find_country(
    country_code: @address.country_code,
    zip: @address.zip,
  )

  return if suggested_country.nil? ||
    suggested_country.iso_code == @address.country_code

  build_concern(build_suggestion(suggested_country.iso_code))
end