class Lite::Address::Format
Public Instance Methods
==(other)
click to toggle source
# File lib/lite/address/format.rb, line 78 def ==(other) to_s == other.to_s end
country_code()
click to toggle source
# File lib/lite/address/format.rb, line 21 def country_code country.alpha2 end
Also aliased as: alpha2
country_name()
click to toggle source
# File lib/lite/address/format.rb, line 25 def country_name country.name end
full_postal_code()
click to toggle source
# File lib/lite/address/format.rb, line 33 def full_postal_code return if postal_code.nil? @full_postal_code ||= [postal_code, postal_code_ext].compact.join('-') end
intersection?()
click to toggle source
# File lib/lite/address/format.rb, line 29 def intersection? !!street && !!street2 end
line1(str = +'')
click to toggle source
# File lib/lite/address/format.rb, line 39 def line1(str = +'') parts = intersection? ? intersection_line1 : address_line1 str + parts.compact.join(' ').strip end
line2(str = +'')
click to toggle source
# File lib/lite/address/format.rb, line 44 def line2(str = +'') str += [city, state].compact.join(', ') str << " #{full_postal_code}" if postal_code str.strip end
state_name()
click to toggle source
# File lib/lite/address/format.rb, line 50 def state_name list.subdivision_map[state] end
to_h()
click to toggle source
# File lib/lite/address/format.rb, line 54 def to_h @to_h ||= Lite::Address::FORMAT_KEYS.each_with_object({}) do |key, hash| hash[key] = public_send(key) end end
to_s(format = :default)
click to toggle source
# File lib/lite/address/format.rb, line 60 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)
click to toggle source
# File lib/lite/address/format.rb, line 68 def to_snail(prefixes: [], include_country: false) prefixes.push(line1, line2) prefixes.push(country_name) if include_country prefixes.compact.join("\n") end
to_ukey()
click to toggle source
# File lib/lite/address/format.rb, line 74 def to_ukey Lite::Address::Ukey.generate(to_s) end
Private Instance Methods
address_line1()
click to toggle source
rubocop:disable Metrics/AbcSize
# File lib/lite/address/format.rb, line 88 def address_line1 parts = [] parts << number parts << prefix parts << street parts << street_type unless redundant_street_type parts << suffix parts << unit_prefix # http://pe.usps.gov/cpim/ftp/pubs/Pub28/pub28.pdf pg28 parts << (unit_prefix ? unit : "\# #{unit}") if unit parts end
intersection_line1()
click to toggle source
# File lib/lite/address/format.rb, line 101 def intersection_line1 parts = [] parts << prefix parts << street parts << street_type parts << suffix parts << 'and' parts << prefix2 parts << street2 parts << street_type2 parts << suffix2 parts end