Class: Lite::Address::Format

Inherits:
Struct
  • Object
show all
Defined in:
lib/lite/address/format.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#listObject

Returns the value of attribute list

Returns:

  • (Object)

    the current value of 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_codeObject Also known as: alpha2



13
14
15
# File 'lib/lite/address/format.rb', line 13

def country_code
  country.alpha2
end

#country_nameObject



17
18
19
# File 'lib/lite/address/format.rb', line 17

def country_name
  country.iso_short_name
end

#full_postal_codeObject



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

Returns:

  • (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_nameObject



42
43
44
# File 'lib/lite/address/format.rb', line 42

def state_name
  list.subdivision_map[state]
end

#to_hObject



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

#to_ukeyObject



66
67
68
# File 'lib/lite/address/format.rb', line 66

def to_ukey
  Lite::Address::Ukey.generate(to_s)
end