Class: LocalPostal::Address
- Inherits:
-
Object
- Object
- LocalPostal::Address
- Includes:
- ActiveModel::Model
- Defined in:
- lib/local_postal/address.rb
Instance Attribute Summary collapse
-
#city ⇒ Object
Returns the value of attribute city.
-
#company ⇒ Object
Returns the value of attribute company.
-
#country ⇒ Object
Returns the value of attribute country.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#name ⇒ Object
Returns the value of attribute name.
-
#postal_code ⇒ Object
Returns the value of attribute postal_code.
-
#region ⇒ Object
Returns the value of attribute region.
-
#secondary_address ⇒ Object
Returns the value of attribute secondary_address.
-
#street_address ⇒ Object
Returns the value of attribute street_address.
Class Method Summary collapse
-
.formatting_variables_lookup_table ⇒ Hash
Maps the universal fields used in the formatting rules to the more commonly used field names that Address uses.
Instance Method Summary collapse
-
#country_code ⇒ String
The 2-character ISO 3166 country code for this address.
-
#lines ⇒ Array
The address’ lines as they should appear on the parcel.
Instance Attribute Details
#city ⇒ Object
Returns the value of attribute city.
5 6 7 |
# File 'lib/local_postal/address.rb', line 5 def city @city end |
#company ⇒ Object
Returns the value of attribute company.
4 5 6 |
# File 'lib/local_postal/address.rb', line 4 def company @company end |
#country ⇒ Object
Returns the value of attribute country.
8 9 10 |
# File 'lib/local_postal/address.rb', line 8 def country @country end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
8 9 10 |
# File 'lib/local_postal/address.rb', line 8 def format @format end |
#name ⇒ Object
Returns the value of attribute name.
4 5 6 |
# File 'lib/local_postal/address.rb', line 4 def name @name end |
#postal_code ⇒ Object
Returns the value of attribute postal_code.
6 7 8 |
# File 'lib/local_postal/address.rb', line 6 def postal_code @postal_code end |
#region ⇒ Object
Returns the value of attribute region.
5 6 7 |
# File 'lib/local_postal/address.rb', line 5 def region @region end |
#secondary_address ⇒ Object
Returns the value of attribute secondary_address.
5 6 7 |
# File 'lib/local_postal/address.rb', line 5 def secondary_address @secondary_address end |
#street_address ⇒ Object
Returns the value of attribute street_address.
5 6 7 |
# File 'lib/local_postal/address.rb', line 5 def street_address @street_address end |
Class Method Details
.formatting_variables_lookup_table ⇒ Hash
Maps the universal fields used in the formatting rules to the more commonly used field names that Address uses.
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/local_postal/address.rb', line 54 def self.formatting_variables_lookup_table { :recipient => :name, :organization => :company, :addressLine1 => :street_address, :addressLine2 => :secondary_address, :postalCode => :postal_code, :locality => :city, :administrativeArea => :region, :sortingCode => nil, :dependentLocality => nil } end |
Instance Method Details
#country_code ⇒ String
The 2-character ISO 3166 country code for this address.
19 20 21 22 23 24 25 |
# File 'lib/local_postal/address.rb', line 19 def country_code cc = carmen_country return if cc.nil? cc.code.upcase if cc.code.is_a?(String) end |
#lines ⇒ Array
The address’ lines as they should appear on the parcel.
30 31 32 33 34 |
# File 'lib/local_postal/address.rb', line 30 def lines address = format.apply(formatting_values) country_name = Carmen::Country.coded(country_code).name.upcase address.split("\n").reject {|line| line.strip.empty? } + [country_name] end |