Class: AtlasEngine::AddressValidation::ZipTruncator
- Inherits:
-
Object
- Object
- AtlasEngine::AddressValidation::ZipTruncator
- Extended by:
- T::Sig
- Defined in:
- app/models/atlas_engine/address_validation/zip_truncator.rb
Instance Method Summary collapse
-
#initialize(country_code:) ⇒ ZipTruncator
constructor
A new instance of ZipTruncator.
- #truncate(zip:, country_code: nil) ⇒ Object
Constructor Details
#initialize(country_code:) ⇒ ZipTruncator
Returns a new instance of ZipTruncator.
10 11 12 |
# File 'app/models/atlas_engine/address_validation/zip_truncator.rb', line 10 def initialize(country_code:) @country_code = T.let(country_code, String) end |
Instance Method Details
#truncate(zip:, country_code: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/atlas_engine/address_validation/zip_truncator.rb', line 17 def truncate(zip:, country_code: nil) return if zip.nil? code = (country_code || @country_code).to_s.upcase case code when "IE" T.must(zip[..2]) # our data only has the routing key (first part) when "US" T.must(zip[..4]) # our data only has 5-digit ZIP, not 9-digit ZIP+4 when String zip end end |