lib/indirizzo/address.rb in Indirizzo-0.1.5 vs lib/indirizzo/address.rb in Indirizzo-0.1.7
- old
+ new
@@ -1,7 +1,6 @@
require 'indirizzo/constants'
-require 'awesome_print'
module Indirizzo
# Defines the matching of parsed address tokens.
Match = {
# FIXME: shouldn't have to anchor :number and :zip at start/end
@@ -86,14 +85,14 @@
@state = text[:region]
if @state.length > 2
# full_state = @state.strip # special case: New York
@state = State[@state]
end
- elsif !text[:country].nil?
- @state = text[:country]
elsif !text[:state].nil?
@state = text[:state]
+ elsif !text[:country].nil?
+ @state = text[:country]
end
@zip = text[:postal_code]
@plus4 = text[:plus4]
if !@zip
@@ -261,20 +260,18 @@
strings
end
def city_parts
strings = []
- @city.map {|string|
+ @city.map do |string|
tokens = string.split(" ")
strings |= (0...tokens.length).to_a.reverse.map {|i|
(i...tokens.length).map {|j| tokens[i..j].join(" ")}}.flatten
- }
+ end
# Don't return strings that consist solely of abbreviations.
# NOTE: Is this a micro-optimization that has edge cases that will break?
# Answer: Yes, it breaks on "Prairie"
- good_strings = strings.reject {|s| Std_Abbr.key? s}
- strings = good_strings if !good_strings.empty?
- strings.uniq
+ strings.reject { |s| Std_Abbr.key?(s) }.uniq
end
def city= (strings)
# NOTE: This will still fail on: 100 Broome St, 33333 (if 33333 is
# Broome, MT or what)