Skip to content

Commit

Permalink
extract city class for #city_parts
Browse files Browse the repository at this point in the history
  • Loading branch information
Dave Worth committed May 5, 2013
1 parent 1352daf commit 3636c08
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
11 changes: 1 addition & 10 deletions lib/indirizzo/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,16 +241,7 @@ def remove_noise_words(strings)
end

def city_parts
strings = []
@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"
strings.reject { |s| Std_Abbr.key?(s) }.uniq
City.city_parts(@city)
end

def city= (strings)
Expand Down
17 changes: 17 additions & 0 deletions lib/indirizzo/city.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Indirizzo
class City
def self.city_parts(city)
strings = []
city.map do |string|
tokens = string.split(" ")
strings |= (0...tokens.length).to_a.reverse.map do |i|
(i...tokens.length).map {|j| tokens[i..j].join(" ")}
end.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"
strings.reject { |s| Std_Abbr.key?(s) }.uniq
end
end
end

0 comments on commit 3636c08

Please sign in to comment.