class Lite::Address::List

Attributes

country[R]

Public Class Methods

new(country) click to toggle source
# File lib/lite/address/list.rb, line 11
def initialize(country)
  @country = country
end

Public Instance Methods

cardinal_codes() click to toggle source
# File lib/lite/address/list.rb, line 15
def cardinal_codes
  @cardinal_codes ||= cardinal_types.invert
end
cardinal_types() click to toggle source
# File lib/lite/address/list.rb, line 19
def cardinal_types
  @cardinal_types ||= begin
    file_path = File.expand_path('types/cardinal.yml', File.dirname(__FILE__))
    YAML.load_file(file_path)
  end
end
state_codes()
Alias for: subdivision_codes
state_map()
Alias for: subdivision_map
state_names()
Alias for: subdivision_names
street_type_regexps() click to toggle source
# File lib/lite/address/list.rb, line 33
def street_type_regexps
  @street_type_regexps ||= street_types.each_with_object({}) do |(type, abbr), hash|
    hash[abbr] = /\b(?:#{abbr}|#{::Regexp.quote(type)})\b/ix
  end
end
street_types() click to toggle source
# File lib/lite/address/list.rb, line 26
def street_types
  @street_types ||= begin
    file_path = File.expand_path('types/street.yml', File.dirname(__FILE__))
    YAML.load_file(file_path)
  end
end
subdivision_codes() click to toggle source
# File lib/lite/address/list.rb, line 39
def subdivision_codes
  @subdivision_codes ||= subdivision_names.invert
end
Also aliased as: state_codes
subdivision_map() click to toggle source
# File lib/lite/address/list.rb, line 43
def subdivision_map
  @subdivision_map ||= country.subdivisions.transform_values(&:name)
end
Also aliased as: state_map
subdivision_names() click to toggle source
# File lib/lite/address/list.rb, line 47
def subdivision_names
  @subdivision_names ||= country.subdivisions.each_with_object({}) do |(code, sub), hash|
    hash[sub.name.downcase] = code
  end
end
Also aliased as: state_names
unit_abbr_numbered_regexps() click to toggle source
# File lib/lite/address/list.rb, line 58
def unit_abbr_numbered_regexps
  @unit_abbr_numbered_regexps ||= {
    'Apt' => /(?:ap|dep)(?:ar)?t(?:me?nt)?/i,
    'PO Box' => /p\W*[om]\W*b(?:ox)?/i,
    'Bldg' => /bu?i?ldi?n?g/i,
    'Dept' => /dep(artmen)?t/i,
    'Floor' => /flo*r?/i,
    'Hanger' => /ha?nga?r/i,
    'Lot' => /lo?t/i,
    'Room' => /ro*m/i,
    'Pier' => /pier/i,
    'Slip' => /slip/i,
    'Space' => /spa?ce?/i,
    'Stop' => /stop/i,
    'Drawer' => /drawer/i,
    'Suite' => /su?i?te/i,
    'Trailer' => /tra?i?le?r/i,
    'Box' => /\w*(?<!po\W)box/i,
    'Unit' => /uni?t/i
  }
end
unit_abbr_regexps() click to toggle source
# File lib/lite/address/list.rb, line 53
def unit_abbr_regexps
  # http://pe.usps.com/text/pub28/pub28c2_003
  @unit_abbr_regexps ||= unit_abbr_numbered_regexps.merge(unit_abbr_unnumbered_regexps)
end
unit_abbr_unnumbered_regexps() click to toggle source
# File lib/lite/address/list.rb, line 80
def unit_abbr_unnumbered_regexps
  @unit_abbr_unnumbered_regexps ||= {
    'Basement' => /ba?se?me?n?t/i,
    'Front' => /fro?nt/i,
    'Lobby' => /lo?bby/i,
    'Lower' => /lowe?r/i,
    'Office' => /off?i?ce?/i,
    'PH' => /pe?n?t?ho?u?s?e?/i,
    'Rear' => /rear/i,
    'Side' => /side/i,
    'Upper' => /uppe?r/i
  }
end