Class: LocalPostal::Address

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
lib/local_postal/address.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cityObject

Returns the value of attribute city.



5
6
7
# File 'lib/local_postal/address.rb', line 5

def city
  @city
end

#companyObject

Returns the value of attribute company.



4
5
6
# File 'lib/local_postal/address.rb', line 4

def company
  @company
end

#countryObject

Returns the value of attribute country.



8
9
10
# File 'lib/local_postal/address.rb', line 8

def country
  @country
end

#formatObject (readonly)

Returns the value of attribute format.



8
9
10
# File 'lib/local_postal/address.rb', line 8

def format
  @format
end

#nameObject

Returns the value of attribute name.



4
5
6
# File 'lib/local_postal/address.rb', line 4

def name
  @name
end

#postal_codeObject

Returns the value of attribute postal_code.



6
7
8
# File 'lib/local_postal/address.rb', line 6

def postal_code
  @postal_code
end

#regionObject

Returns the value of attribute region.



5
6
7
# File 'lib/local_postal/address.rb', line 5

def region
  @region
end

#secondary_addressObject

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_addressObject

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_tableHash

Maps the universal fields used in the formatting rules to the more commonly used field names that Address uses.

Returns:

  • (Hash)

    Keys are formatting rule fields; values are Address fields.



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_codeString

The 2-character ISO 3166 country code for this address.

Returns:

  • (String)

    The country’s ISO code or nil when unavailable.



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

#linesArray

The address’ lines as they should appear on the parcel.

Returns:

  • (Array)

    The address lines.



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