class ValidatesZipcode::Formatter

Constants

WORD_CHAR_AND_DIGIT
ZIPCODES_TRANSFORMATIONS

Public Class Methods

new(args = {}) click to toggle source
# File lib/validates_zipcode/formatter.rb, line 37
def initialize(args = {})
  @zipcode        = args.fetch(:zipcode).to_s
  @country_alpha2 = args.fetch(:country_alpha2).to_s.upcase.to_sym
end

Public Instance Methods

format() click to toggle source
# File lib/validates_zipcode/formatter.rb, line 42
def format
  transformation = ZIPCODES_TRANSFORMATIONS[@country_alpha2]
  case transformation
  when Proc
    transformation.call(@zipcode)
  when Symbol
    ZIPCODES_TRANSFORMATIONS[transformation].call(@zipcode)
  else
    @zipcode.strip
  end
end