Module: DataMapper::Address::US
- Defined in:
- lib/dm-address/us.rb
Overview
Include in a DataMapper::Resource model to add fields and methods for a US-style address.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEFAULT_REQUIRED_FIELDS =
[ :street, :city, :state, :postal_code, :country ]
Class Method Summary collapse
Instance Method Summary collapse
-
#block(newline = "\n", include_country = , include_phone = ) ⇒ Object
Nicely formatted address block (optionally includes country and phone).
Class Method Details
.included(klass) ⇒ Object
11 12 13 |
# File 'lib/dm-address/us.rb', line 11 def included(klass) klass.extend(ClassMethods) end |
Instance Method Details
#block(newline = "\n", include_country = , include_phone = ) ⇒ Object
Nicely formatted address block (optionally includes country and phone)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/dm-address/us.rb', line 56 def block(newline = "\n", include_country = DataMapper::Address.config[:include_country], include_phone = DataMapper::Address.config[:include_phone]) fields = [] %w{ name company street street_2 }.each do |fld| value = attribute_get(fld) fields << value unless value.blank? end fields << "#{self.city}, #{self.state} #{ZipCode.new(self.postal_code).to_s}" fields << self.country if include_country fields << PhoneNumber.new(self.phone).to_s if include_phone && !self.phone.blank? fields.join(newline) end |