Class: Lite::Address::Format
- Inherits:
-
Struct
- Object
- Struct
- Lite::Address::Format
- Defined in:
- lib/lite/address/format.rb
Instance Attribute Summary collapse
-
#list ⇒ Object
Returns the value of attribute list.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #country_code ⇒ Object (also: #alpha2)
- #country_name ⇒ Object
- #full_postal_code ⇒ Object
- #intersection? ⇒ Boolean
- #line1(str = +"")) ⇒ Object
- #line2(str = +"")) ⇒ Object
- #state_name ⇒ Object
- #to_h ⇒ Object
- #to_s(format = :default) ⇒ Object
- #to_snail(prefixes: [], include_country: false) ⇒ Object
- #to_ukey ⇒ Object
Instance Attribute Details
#list ⇒ Object
Returns the value of attribute list
11 12 13 |
# File 'lib/lite/address/format.rb', line 11 def list @list end |
Instance Method Details
#==(other) ⇒ Object
70 71 72 |
# File 'lib/lite/address/format.rb', line 70 def ==(other) to_s == other.to_s end |
#country_code ⇒ Object Also known as: alpha2
13 14 15 |
# File 'lib/lite/address/format.rb', line 13 def country_code country.alpha2 end |
#country_name ⇒ Object
17 18 19 |
# File 'lib/lite/address/format.rb', line 17 def country_name country.iso_short_name end |
#full_postal_code ⇒ Object
25 26 27 28 29 |
# File 'lib/lite/address/format.rb', line 25 def full_postal_code return if postal_code.nil? @full_postal_code ||= [postal_code, postal_code_ext].compact.join("-") end |
#intersection? ⇒ Boolean
21 22 23 |
# File 'lib/lite/address/format.rb', line 21 def intersection? !!street && !!street2 end |
#line1(str = +"")) ⇒ Object
31 32 33 34 |
# File 'lib/lite/address/format.rb', line 31 def line1(str = +"") parts = intersection? ? intersection_line1 : address_line1 str + parts.compact.join(" ").strip end |
#line2(str = +"")) ⇒ Object
36 37 38 39 40 |
# File 'lib/lite/address/format.rb', line 36 def line2(str = +"") str += [city, state].compact.join(", ") str << " #{full_postal_code}" if postal_code str.strip end |
#state_name ⇒ Object
42 43 44 |
# File 'lib/lite/address/format.rb', line 42 def state_name list.subdivision_map[state] end |
#to_h ⇒ Object
46 47 48 49 50 |
# File 'lib/lite/address/format.rb', line 46 def to_h @to_h ||= Lite::Address::PARTS.each_with_object({}) do |key, hash| hash[key] = public_send(key) end end |
#to_s(format = :default) ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/lite/address/format.rb', line 52 def to_s(format = :default) case format when :line1 then line1 when :line2 then line2 else [line1, line2].reject(&:empty?).join(", ") end end |
#to_snail(prefixes: [], include_country: false) ⇒ Object
60 61 62 63 64 |
# File 'lib/lite/address/format.rb', line 60 def to_snail(prefixes: [], include_country: false) prefixes.push(line1, line2) prefixes.push(country_name) if include_country prefixes.compact.join("\n") end |