forked from synup/indirizzo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dave Worth
committed
May 5, 2013
1 parent
1352daf
commit 3636c08
Showing
2 changed files
with
18 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |