Class: PostalCoder::Formats::USZipCode
- Inherits:
-
AbstractFormat
- Object
- AbstractFormat
- PostalCoder::Formats::USZipCode
- Defined in:
- lib/postalcoder/formats.rb
Instance Attribute Summary
Attributes inherited from AbstractFormat
Instance Method Summary collapse
Methods inherited from AbstractFormat
Constructor Details
This class inherits a constructor from PostalCoder::Formats::AbstractFormat
Instance Method Details
#has_valid_form? ⇒ 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_s ⇒ Object
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 |