Class: Postal::Address
- Inherits:
-
Object
- Object
- Postal::Address
- Defined in:
- lib/postal_address/address.rb
Constant Summary collapse
- Fields =
%i(recipient street zip state city country country_code).freeze
Instance Method Summary collapse
- #country ⇒ Object
- #country_code=(code) ⇒ Object
-
#initialize(**attrs) {|_self| ... } ⇒ Address
constructor
A new instance of Address.
- #to_h ⇒ Object
- #to_html(**params) ⇒ Object
- #to_s(**params) ⇒ Object
- #values ⇒ Object
Constructor Details
#initialize(**attrs) {|_self| ... } ⇒ Address
Returns a new instance of Address.
7 8 9 10 |
# File 'lib/postal_address/address.rb', line 7 def initialize(**attrs, &block) attrs.each { |k,v| public_send("#{k}=", v) if respond_to?("#{k}=") } yield self if block_given? end |
Instance Method Details
#country ⇒ Object
16 17 18 |
# File 'lib/postal_address/address.rb', line 16 def country Postal.country_names[country_code] end |
#country_code=(code) ⇒ Object
12 13 14 |
# File 'lib/postal_address/address.rb', line 12 def country_code=(code) @country_code = Postal.sanitize(code) end |
#to_h ⇒ Object
24 25 26 |
# File 'lib/postal_address/address.rb', line 24 def to_h Fields.zip(values).to_h end |
#to_html(**params) ⇒ Object
32 33 34 |
# File 'lib/postal_address/address.rb', line 32 def to_html(**params) AddressFormatter::HTML.new(to_h).render(params) end |
#to_s(**params) ⇒ Object
28 29 30 |
# File 'lib/postal_address/address.rb', line 28 def to_s(**params) AddressFormatter::Text.new(to_h).render(params) end |
#values ⇒ Object
20 21 22 |
# File 'lib/postal_address/address.rb', line 20 def values Fields.map(&method(:public_send)) end |