Class: PostalCoder::Formats::USZipCode

Inherits:
AbstractFormat show all
Defined in:
lib/postalcoder/formats.rb

Instance Attribute Summary

Attributes inherited from AbstractFormat

#value

Instance Method Summary collapse

Methods inherited from AbstractFormat

#cleanup, #initialize

Constructor Details

This class inherits a constructor from PostalCoder::Formats::AbstractFormat

Instance Method Details

#has_valid_form?Boolean

Returns:

  • (Boolean)


112
113
114
# File 'lib/postalcoder/formats.rb', line 112

def has_valid_form?
  value =~ /\A([0-9]{5}|[0-9]{9})\Z/
end

#to_sObject



103
104
105
106
107
108
109
110
# File 'lib/postalcoder/formats.rb', line 103

def to_s
  case value.length
  when 5
    value
  when 9
    "#{value[0,5]}-#{value[5,4]}"
  end
end