Class: Lite::Address::List
- Inherits:
-
Object
- Object
- Lite::Address::List
- Defined in:
- lib/lite/address/list.rb
Instance Attribute Summary collapse
-
#country ⇒ Object
readonly
Returns the value of attribute country.
Instance Method Summary collapse
- #cardinal_codes ⇒ Object
- #cardinal_types ⇒ Object
-
#initialize(country) ⇒ List
constructor
A new instance of List.
- #street_type_regexps ⇒ Object
- #street_types ⇒ Object
- #subdivision_codes ⇒ Object (also: #state_codes)
- #subdivision_map ⇒ Object (also: #state_map)
- #subdivision_names ⇒ Object (also: #state_names)
- #unit_abbr_numbered_regexps ⇒ Object
- #unit_abbr_regexps ⇒ Object
- #unit_abbr_unnumbered_regexps ⇒ Object
Constructor Details
#initialize(country) ⇒ List
Returns a new instance of List.
11 12 13 |
# File 'lib/lite/address/list.rb', line 11 def initialize(country) @country = country end |
Instance Attribute Details
#country ⇒ Object (readonly)
Returns the value of attribute country.
9 10 11 |
# File 'lib/lite/address/list.rb', line 9 def country @country end |
Instance Method Details
#cardinal_codes ⇒ Object
15 16 17 |
# File 'lib/lite/address/list.rb', line 15 def cardinal_codes @cardinal_codes ||= cardinal_types.invert end |
#cardinal_types ⇒ Object
19 20 21 22 23 24 |
# File 'lib/lite/address/list.rb', line 19 def cardinal_types @cardinal_types ||= begin file_path = File.("types/cardinal.yml", File.dirname(__FILE__)) YAML.load_file(file_path) end end |
#street_type_regexps ⇒ Object
33 34 35 36 37 |
# 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 ⇒ Object
26 27 28 29 30 31 |
# File 'lib/lite/address/list.rb', line 26 def street_types @street_types ||= begin file_path = File.("types/street.yml", File.dirname(__FILE__)) YAML.load_file(file_path) end end |
#subdivision_codes ⇒ Object Also known as: state_codes
39 40 41 |
# File 'lib/lite/address/list.rb', line 39 def subdivision_codes @subdivision_codes ||= subdivision_names.invert end |
#subdivision_map ⇒ Object Also known as: state_map
43 44 45 |
# File 'lib/lite/address/list.rb', line 43 def subdivision_map @subdivision_map ||= country.subdivisions.transform_values(&:name) end |
#subdivision_names ⇒ Object Also known as: state_names
47 48 49 50 51 |
# 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 |
#unit_abbr_numbered_regexps ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# 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 ⇒ Object
53 54 55 56 |
# 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 ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# 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 |