Class: DataMapper::Address::ZipCode
- Inherits:
-
String
- Object
- String
- DataMapper::Address::ZipCode
- Defined in:
- lib/dm-address/zip_code.rb
Instance Method Summary collapse
-
#initialize(s) ⇒ ZipCode
constructor
Remove all non-digits from given zip code.
-
#to_s(format = nil) ⇒ Object
ZipCode formatted as #####-#### or #####.
Constructor Details
#initialize(s) ⇒ ZipCode
Remove all non-digits from given zip code
5 6 7 |
# File 'lib/dm-address/zip_code.rb', line 5 def initialize(s) super((s || '').to_str.gsub(/\D+/, '')) end |
Instance Method Details
#to_s(format = nil) ⇒ Object
ZipCode formatted as #####-#### or #####
10 11 12 13 14 |
# File 'lib/dm-address/zip_code.rb', line 10 def to_s(format = nil) return '' if to_str.empty? return to_str if to_str.length == 5 "#{to_str[0..4]}-#{to_str[5..8]}" end |