Indirizzo 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +10 -1
- data/Indirizzo.gemspec +1 -1
- data/Rakefile +3 -3
- data/lib/indirizzo.rb +1 -1
- data/lib/indirizzo/address.rb +46 -40
- data/lib/indirizzo/constants.rb +4 -2
- data/test/test_address.rb +197 -146
- metadata +7 -7
data/Gemfile
CHANGED
data/Indirizzo.gemspec
CHANGED
data/Rakefile
CHANGED
data/lib/indirizzo.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require '
|
1
|
+
require 'indirizzo/address'
|
data/lib/indirizzo/address.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'indirizzo/constants'
|
2
|
+
require 'awesome_print'
|
2
3
|
|
3
4
|
module Indirizzo
|
4
5
|
# Defines the matching of parsed address tokens.
|
@@ -6,9 +7,9 @@ module Indirizzo
|
|
6
7
|
# FIXME: shouldn't have to anchor :number and :zip at start/end
|
7
8
|
:number => /^(\d+\W|[a-z]+)?(\d+)([a-z]?)\b/io,
|
8
9
|
:street => /(?:\b(?:\d+\w*|[a-z'-]+)\s*)+/io,
|
9
|
-
:city => /(?:\b[a-z'-]+\s*)+/io,
|
10
|
-
:state =>
|
11
|
-
:zip =>
|
10
|
+
:city => /(?:\b[a-z][a-z'-]+\s*)+/io,
|
11
|
+
:state => State.regexp,
|
12
|
+
:zip => /\b(\d{5})(?:-(\d{4}))?\b/o,
|
12
13
|
:at => /\s(at|@|and|&)\s/io,
|
13
14
|
:po_box => /\b[P|p]*(OST|ost)*\.*\s*[O|o|0]*(ffice|FFICE)*\.*\s*[B|b][O|o|0][X|x]\b/
|
14
15
|
}
|
@@ -23,6 +24,7 @@ module Indirizzo
|
|
23
24
|
attr_accessor :city
|
24
25
|
attr_accessor :state
|
25
26
|
attr_accessor :zip, :plus4
|
27
|
+
attr_accessor :country
|
26
28
|
|
27
29
|
# Takes an address or place name string as its sole argument.
|
28
30
|
def initialize (text)
|
@@ -122,55 +124,51 @@ module Indirizzo
|
|
122
124
|
strings
|
123
125
|
end
|
124
126
|
|
125
|
-
def parse_zip(regex_match, text)
|
126
|
-
idx = text.rindex(regex_match)
|
127
|
-
text[idx...idx+regex_match.length] = ""
|
128
|
-
text.sub! /\s*,?\s*$/o, ""
|
129
|
-
@zip, @plus4 = @zip.map {|s|s.strip}
|
130
|
-
text
|
131
|
-
end
|
132
|
-
|
133
127
|
def parse_state(regex_match, text)
|
134
128
|
idx = text.rindex(regex_match)
|
135
|
-
text[idx...idx+regex_match.length] = ""
|
136
|
-
text.sub! /\s*,?\s*$/o, ""
|
137
129
|
@full_state = @state[0].strip # special case: New York
|
138
130
|
@state = State[@full_state]
|
139
|
-
text
|
140
|
-
end
|
141
|
-
|
142
|
-
def parse_number(regex_match, text)
|
143
|
-
# FIXME: What if this string appears twice?
|
144
|
-
idx = text.index(regex_match)
|
145
|
-
text[idx...idx+regex_match.length] = ""
|
146
|
-
text.sub! /^\s*,?\s*/o, ""
|
147
|
-
@prenum, @number, @sufnum = @number.map {|s| s and s.strip}
|
131
|
+
@city = "Washington" if @state == "DC" && text[idx...idx+regex_match.length] =~ /washington\s+d\.?c\.?/i
|
148
132
|
text
|
149
133
|
end
|
150
134
|
|
151
135
|
def parse
|
152
136
|
text = @text.clone.downcase
|
153
137
|
|
154
|
-
@zip = text.scan(Match[:zip])
|
138
|
+
@zip = text.scan(Match[:zip]).last
|
155
139
|
if @zip
|
156
|
-
|
140
|
+
last_match = $&
|
141
|
+
zip_index = text.rindex(last_match)
|
142
|
+
zip_end_index = zip_index + last_match.length - 1
|
143
|
+
@zip, @plus4 = @zip.map {|s| s and s.strip }
|
157
144
|
else
|
158
145
|
@zip = @plus4 = ""
|
146
|
+
zip_index = text.length
|
147
|
+
zip_end_index = -1
|
159
148
|
end
|
160
149
|
|
161
|
-
@
|
150
|
+
@country = @text[zip_end_index+1..-1].sub(/^\s*,\s*/, '').strip
|
151
|
+
@country = nil if @country == text
|
152
|
+
|
153
|
+
@state = text.scan(Match[:state]).last
|
162
154
|
if @state
|
163
|
-
|
155
|
+
last_match = $&
|
156
|
+
state_index = text.rindex(last_match)
|
157
|
+
text = parse_state(last_match, text)
|
164
158
|
else
|
165
159
|
@full_state = ""
|
166
160
|
@state = ""
|
167
161
|
end
|
168
162
|
|
169
|
-
@number = text.scan(Match[:number])
|
163
|
+
@number = text.scan(Match[:number]).first
|
170
164
|
# FIXME: 230 Fish And Game Rd, Hudson NY 12534
|
171
165
|
if @number # and not intersection?
|
172
|
-
|
166
|
+
last_match = $&
|
167
|
+
number_index = text.index(last_match)
|
168
|
+
number_end_index = number_index + last_match.length - 1
|
169
|
+
@prenum, @number, @sufnum = @number.map {|s| s and s.strip}
|
173
170
|
else
|
171
|
+
number_end_index = -1
|
174
172
|
@prenum = @number = @sufnum = ""
|
175
173
|
end
|
176
174
|
|
@@ -179,24 +177,32 @@ module Indirizzo
|
|
179
177
|
# Sault Ste. Marie
|
180
178
|
|
181
179
|
# FIXME: PO Box should geocode to ZIP
|
182
|
-
|
180
|
+
street_search_end_index = [state_index,zip_index,text.length].reject(&:nil?).min-1
|
181
|
+
@street = text[number_end_index+1..street_search_end_index].scan(Match[:street]).map { |s| s and s.strip }
|
182
|
+
|
183
183
|
@street = expand_streets(@street)
|
184
184
|
# SPECIAL CASE: 1600 Pennsylvania 20050
|
185
185
|
@street << @full_state if @street.empty? and @state.downcase != @full_state.downcase
|
186
186
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
187
|
+
street_end_index = @street.map { |s| text.rindex(s) }.reject(&:nil?).min||0
|
188
|
+
|
189
|
+
if @city.nil? || @city.empty?
|
190
|
+
@city = text[street_end_index..street_search_end_index+1].scan(Match[:city])
|
191
|
+
if !@city.empty?
|
192
|
+
#@city = [@city[-1].strip]
|
193
|
+
@city = [@city.last.strip]
|
194
|
+
add = @city.map {|item| item.gsub(Name_Abbr.regexp) {|m| Name_Abbr[m]}}
|
195
|
+
@city |= add
|
196
|
+
@city.map! {|s| s.downcase}
|
197
|
+
@city.uniq!
|
198
|
+
else
|
199
|
+
@city = []
|
200
|
+
end
|
201
|
+
|
202
|
+
# SPECIAL CASE: no city, but a state with the same name. e.g. "New York"
|
203
|
+
@city << @full_state if @state.downcase != @full_state.downcase
|
196
204
|
end
|
197
205
|
|
198
|
-
# SPECIAL CASE: no city, but a state with the same name. e.g. "New York"
|
199
|
-
@city << @full_state if @state.downcase != @full_state.downcase
|
200
206
|
end
|
201
207
|
|
202
208
|
def expand_streets(street)
|
data/lib/indirizzo/constants.rb
CHANGED
@@ -20,10 +20,10 @@ module Indirizzo
|
|
20
20
|
# whitespace-delimited prefixes to keys and values in the two-way Map.
|
21
21
|
def build_partial
|
22
22
|
@partial = Set.new()
|
23
|
-
[keys, values].flatten.each
|
23
|
+
[keys, values].flatten.each do |item|
|
24
24
|
@partial << item.downcase
|
25
25
|
item.downcase.split.each {|token| @partial << token}
|
26
|
-
|
26
|
+
end
|
27
27
|
end
|
28
28
|
def build_match
|
29
29
|
@regexp = Regexp.new(
|
@@ -612,6 +612,8 @@ module Indirizzo
|
|
612
612
|
"Connecticut" => "CT",
|
613
613
|
"Delaware" => "DE",
|
614
614
|
"District of Columbia" => "DC",
|
615
|
+
"Washington DC" => "DC",
|
616
|
+
"Washington D.C." => "DC",
|
615
617
|
"Federated States of Micronesia" => "FM",
|
616
618
|
"Florida" => "FL",
|
617
619
|
"Georgia" => "GA",
|
data/test/test_address.rb
CHANGED
@@ -9,18 +9,6 @@ class TestAddress < Test::Unit::TestCase
|
|
9
9
|
addr = Address.new("1600 Pennsylvania Av., Washington DC")
|
10
10
|
assert_equal "1600 Pennsylvania Av, Washington DC", addr.text
|
11
11
|
end
|
12
|
-
def test_clean
|
13
|
-
fixtures = [
|
14
|
-
[ "cleaned text", "cleaned: text!" ],
|
15
|
-
[ "cleaned-text 2", "cleaned-text: #2?" ],
|
16
|
-
[ "it's working 1/2", "~it's working 1/2~" ],
|
17
|
-
[ "it's working, yes", "it's working, yes...?" ],
|
18
|
-
[ "it's working & well", "it's working & well?" ]
|
19
|
-
]
|
20
|
-
fixtures.each {|output, given|
|
21
|
-
assert_equal output, Address.new(given).text
|
22
|
-
}
|
23
|
-
end
|
24
12
|
def test_expand_numbers
|
25
13
|
num_list = ["5", "fifth", "five"]
|
26
14
|
num_list.each {|n|
|
@@ -28,146 +16,12 @@ class TestAddress < Test::Unit::TestCase
|
|
28
16
|
assert_equal num_list, addr.expand_numbers(n).to_a.sort
|
29
17
|
}
|
30
18
|
end
|
31
|
-
def test_city_parse
|
32
|
-
places = [
|
33
|
-
[ "New York, NY", "New York", "NY", "" ],
|
34
|
-
[ "NY", "", "NY", "" ],
|
35
|
-
[ "New York", "New York", "NY", "" ],
|
36
|
-
[ "Philadelphia", "Philadelphia", "", "" ],
|
37
|
-
[ "Philadelphia PA", "Philadelphia", "PA", "" ],
|
38
|
-
[ "Philadelphia, PA", "Philadelphia", "PA", "" ],
|
39
|
-
[ "Philadelphia, Pennsylvania", "Philadelphia", "PA", "" ],
|
40
|
-
[ "Philadelphia, Pennsylvania 19131", "Philadelphia", "PA", "19131" ],
|
41
|
-
[ "Philadelphia 19131", "Philadelphia", "", "19131" ],
|
42
|
-
[ "Pennsylvania 19131", "Pennsylvania", "PA", "19131" ], # kind of a misfeature
|
43
|
-
[ "19131", "", "", "19131" ],
|
44
|
-
[ "19131-9999", "", "", "19131" ],
|
45
|
-
]
|
46
|
-
for fixture in places
|
47
|
-
addr = Address.new fixture[0]
|
48
|
-
[:city, :state, :zip].zip(fixture[1..3]).each {|key,val|
|
49
|
-
result = addr.send key
|
50
|
-
result = [result.downcase] unless result.kind_of? Array
|
51
|
-
if result.empty?
|
52
|
-
assert_equal val, "", key.to_s + " test no result " + fixture.join("/")
|
53
|
-
else
|
54
|
-
assert result.member?(val.downcase), key.to_s + " test " + result.inspect + fixture.join("/")
|
55
|
-
end
|
56
|
-
}
|
57
|
-
end
|
58
|
-
end
|
59
19
|
|
60
20
|
def test_po_box
|
61
21
|
addr_po = Address.new "PO Box 1111 Herndon VA 20171"
|
62
22
|
assert addr_po.po_box?
|
63
23
|
end
|
64
24
|
|
65
|
-
def test_parse
|
66
|
-
addrs = [
|
67
|
-
{:text => "1600 Pennsylvania Av., Washington DC 20050",
|
68
|
-
:number => "1600",
|
69
|
-
:street => "Pennsylvania Ave",
|
70
|
-
:city => "Washington",
|
71
|
-
:state => "DC",
|
72
|
-
:zip => "20050"},
|
73
|
-
|
74
|
-
{:text => "1600 Pennsylvania, Washington DC",
|
75
|
-
:number => "1600",
|
76
|
-
:street => "Pennsylvania",
|
77
|
-
:city => "Washington",
|
78
|
-
:state => "DC"},
|
79
|
-
|
80
|
-
{:text => "1600 Pennsylvania Washington DC",
|
81
|
-
:number => "1600",
|
82
|
-
:street => "Pennsylvania Washington",
|
83
|
-
:city => "Pennsylvania Washington", # FIXME
|
84
|
-
:state => "DC"},
|
85
|
-
|
86
|
-
{:text => "1600 Pennsylvania Washington",
|
87
|
-
:number => "1600",
|
88
|
-
:street => "Pennsylvania",
|
89
|
-
:city => "Washington",
|
90
|
-
:state => "WA"}, # FIXME
|
91
|
-
|
92
|
-
{:text => "1600 Pennsylvania 20050",
|
93
|
-
:number => "1600",
|
94
|
-
:street => "Pennsylvania", # FIXME
|
95
|
-
:zip => "20050"},
|
96
|
-
|
97
|
-
{:text => "1600 Pennsylvania Av, 20050-9999",
|
98
|
-
:number => "1600",
|
99
|
-
:street => "Pennsylvania Ave",
|
100
|
-
:zip => "20050"},
|
101
|
-
|
102
|
-
{:text => "1005 Gravenstein Highway North, Sebastopol CA",
|
103
|
-
:number => "1005",
|
104
|
-
:street => "Gravenstein Hwy N",
|
105
|
-
:city => "Sebastopol",
|
106
|
-
:state => "CA"},
|
107
|
-
|
108
|
-
{:text => "100 N 7th St, Brooklyn",
|
109
|
-
:number => "100",
|
110
|
-
:street => "N 7 St",
|
111
|
-
:city => "Brooklyn"},
|
112
|
-
|
113
|
-
{:text => "100 N Seventh St, Brooklyn",
|
114
|
-
:number => "100",
|
115
|
-
:street => "N 7 St",
|
116
|
-
:city => "Brooklyn"},
|
117
|
-
|
118
|
-
{:text => "100 Central Park West, New York, NY",
|
119
|
-
:number => "100",
|
120
|
-
:street => "Central Park W",
|
121
|
-
:city => "New York",
|
122
|
-
:state => "NY"},
|
123
|
-
|
124
|
-
{:text => "100 Central Park West, 10010",
|
125
|
-
:number => "100",
|
126
|
-
:street => "Central Park W",
|
127
|
-
:zip => "10010"},
|
128
|
-
|
129
|
-
{:text => "1400 Avenue of the Americas, New York, NY 10019",
|
130
|
-
:number => "1400",
|
131
|
-
:street => "Ave of the Americas",
|
132
|
-
:city => "New York",
|
133
|
-
:state => "NY"},
|
134
|
-
|
135
|
-
{:text => "1400 Avenue of the Americas, New York",
|
136
|
-
:number => "1400",
|
137
|
-
:street => "Ave of the Americas",
|
138
|
-
:city => "New York"},
|
139
|
-
|
140
|
-
{:text => "1400 Ave of the Americas, New York",
|
141
|
-
:number => "1400",
|
142
|
-
:street => "Ave of the Americas",
|
143
|
-
:city => "New York"},
|
144
|
-
|
145
|
-
{:text => "1400 Av of the Americas, New York",
|
146
|
-
:number => "1400",
|
147
|
-
:street => "Ave of the Americas",
|
148
|
-
:city => "New York"},
|
149
|
-
|
150
|
-
{:text => "1400 Av of the Americas New York",
|
151
|
-
:number => "1400",
|
152
|
-
:street => "Ave of the Americas",
|
153
|
-
:city => "New York"},
|
154
|
-
|
155
|
-
]
|
156
|
-
for fixture in addrs
|
157
|
-
text = fixture.delete(:text)
|
158
|
-
addr = Address.new(text)
|
159
|
-
for key, val in fixture
|
160
|
-
result = addr.send key
|
161
|
-
if result.kind_of? Array
|
162
|
-
result.map! {|str| str.downcase}
|
163
|
-
assert result.member?(val.downcase), "#{text} (#{key}) = #{result.inspect}"
|
164
|
-
else
|
165
|
-
assert_equal val, result, "#{text} (#{key}) = #{result.inspect}"
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
25
|
def test_skip_parse
|
172
26
|
addresses = [
|
173
27
|
{:street => "1233 Main St", :city => "Springfield", :region => "VA", :postal_code => "12345", :final_number => "1233", :parsed_street => "main st"},
|
@@ -225,4 +79,201 @@ class TestAddress < Test::Unit::TestCase
|
|
225
79
|
assert_equal preparsed_address[:country],address_for_geocode.state
|
226
80
|
end
|
227
81
|
end
|
82
|
+
|
83
|
+
# test cleaning code
|
84
|
+
[
|
85
|
+
[ "cleaned text", "cleaned: text!" ],
|
86
|
+
[ "cleaned-text 2", "cleaned-text: #2?" ],
|
87
|
+
[ "it's working 1/2", "~it's working 1/2~" ],
|
88
|
+
[ "it's working, yes", "it's working, yes...?" ],
|
89
|
+
[ "it's working & well", "it's working & well?" ]
|
90
|
+
].each do |output, given|
|
91
|
+
define_method "test_clean_#{output.tr('-/\'&', '').gsub(/\s+/, '_')}" do
|
92
|
+
assert_equal output, Address.new(given).text
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
# test the city parsing code
|
97
|
+
[
|
98
|
+
[ "New York, NY", "New York", "NY", "" ],
|
99
|
+
[ "NY", "", "NY", "" ],
|
100
|
+
[ "New York", "New York", "NY", "" ],
|
101
|
+
[ "Philadelphia", "Philadelphia", "", "" ],
|
102
|
+
[ "Philadelphia PA", "Philadelphia", "PA", "" ],
|
103
|
+
[ "Philadelphia, PA", "Philadelphia", "PA", "" ],
|
104
|
+
[ "Philadelphia, Pennsylvania", "Philadelphia", "PA", "" ],
|
105
|
+
[ "Philadelphia, Pennsylvania 19131", "Philadelphia", "PA", "19131" ],
|
106
|
+
[ "Philadelphia 19131", "Philadelphia", "", "19131" ],
|
107
|
+
[ "Pennsylvania 19131", "Pennsylvania", "PA", "19131" ], # kind of a misfeature
|
108
|
+
[ "19131", "", "", "19131" ],
|
109
|
+
[ "19131-9999", "", "", "19131" ],
|
110
|
+
].each do |fixture|
|
111
|
+
define_method "test_city_parse_#{fixture[0].gsub(/(?:\s+|[,])/,'_')}" do
|
112
|
+
check_city(fixture)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
def check_city(fixture)
|
117
|
+
addr = Address.new(fixture[0])
|
118
|
+
[:city, :state, :zip].zip(fixture[1..3]).each do |key,val|
|
119
|
+
result = addr.send(key)
|
120
|
+
result = [result.downcase] unless result.kind_of?(Array)
|
121
|
+
if result.empty?
|
122
|
+
assert_equal val, "", key.to_s + " test no result " + fixture.join("/")
|
123
|
+
else
|
124
|
+
assert result.member?(val.downcase), key.to_s + " test " + result.inspect + fixture.join("/")
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
# test address parsing code
|
130
|
+
[
|
131
|
+
{:text => "1600 Pennsylvania Av., Washington DC 20050",
|
132
|
+
:number => "1600",
|
133
|
+
:street => "Pennsylvania Ave",
|
134
|
+
:city => "Washington",
|
135
|
+
:state => "DC",
|
136
|
+
:zip => "20050"},
|
137
|
+
|
138
|
+
{:text => "1600 Pennsylvania, Washington DC",
|
139
|
+
:number => "1600",
|
140
|
+
:street => "Pennsylvania",
|
141
|
+
:city => "Washington",
|
142
|
+
:state => "DC"},
|
143
|
+
|
144
|
+
{:text => "1600 Pennsylvania Washington DC",
|
145
|
+
:number => "1600",
|
146
|
+
:city => "Washington",
|
147
|
+
:street => "Pennsylvania",
|
148
|
+
:state => "DC"},
|
149
|
+
|
150
|
+
{:text => "1600 Pennsylvania Washington",
|
151
|
+
:pending => true,
|
152
|
+
:number => "1600",
|
153
|
+
:street => "Pennsylvania",
|
154
|
+
:city => "Washington",
|
155
|
+
:state => "DC"},
|
156
|
+
|
157
|
+
{:text => "1600 Pennsylvania 20050",
|
158
|
+
:number => "1600",
|
159
|
+
:state => "PA",
|
160
|
+
:zip => "20050"},
|
161
|
+
|
162
|
+
{:text => "1600 Pennsylvania Av, Washington DC 20050-9999",
|
163
|
+
:number => "1600",
|
164
|
+
:state => "DC",
|
165
|
+
:street => "Pennsylvania Ave",
|
166
|
+
:plus4 => "9999",
|
167
|
+
:zip => "20050"},
|
168
|
+
|
169
|
+
{:text => "1600 Pennsylvania Av, 20050-9999",
|
170
|
+
:pending => true,
|
171
|
+
:number => "1600",
|
172
|
+
#:state => "PA",
|
173
|
+
:street => "Pennsylvania Ave",
|
174
|
+
:plus4 => "9999",
|
175
|
+
:zip => "20050"},
|
176
|
+
|
177
|
+
{:text => "1005 Gravenstein Highway North, Sebastopol CA",
|
178
|
+
:number => "1005",
|
179
|
+
:street => "Gravenstein Hwy N",
|
180
|
+
:city => "Sebastopol",
|
181
|
+
:state => "CA"},
|
182
|
+
|
183
|
+
{:text => "100 N 7th St, Brooklyn",
|
184
|
+
:number => "100",
|
185
|
+
:street => "N 7 St",
|
186
|
+
:city => "Brooklyn"},
|
187
|
+
|
188
|
+
{:text => "100 N Seventh St, Brooklyn",
|
189
|
+
:number => "100",
|
190
|
+
:street => "N 7 St",
|
191
|
+
:city => "Brooklyn"},
|
192
|
+
|
193
|
+
{:text => "100 Central Park West, New York, NY",
|
194
|
+
:number => "100",
|
195
|
+
:street => "Central Park W",
|
196
|
+
:city => "New York",
|
197
|
+
:state => "NY"},
|
198
|
+
|
199
|
+
{:text => "100 Central Park West, 10010",
|
200
|
+
:number => "100",
|
201
|
+
:street => "Central Park W",
|
202
|
+
:zip => "10010"},
|
203
|
+
|
204
|
+
{:text => "1400 Avenue of the Americas, New York, NY 10019, US",
|
205
|
+
:number => "1400",
|
206
|
+
:street => "Ave of the Americas",
|
207
|
+
:city => "New York",
|
208
|
+
:state => "NY",
|
209
|
+
:country => "US"},
|
210
|
+
|
211
|
+
{:text => "1400 Avenue of the Americas, New York, NY 10019, USA",
|
212
|
+
:number => "1400",
|
213
|
+
:street => "Ave of the Americas",
|
214
|
+
:city => "New York",
|
215
|
+
:state => "NY",
|
216
|
+
:country => "USA"},
|
217
|
+
|
218
|
+
{:text => "1400 Avenue of the Americas, New York, NY 10019, United States of America ",
|
219
|
+
:number => "1400",
|
220
|
+
:street => "Ave of the Americas",
|
221
|
+
:city => "New York",
|
222
|
+
:state => "NY",
|
223
|
+
:country => "United States of America"},
|
224
|
+
|
225
|
+
{:text => "1400 Avenue of the Americas, New York",
|
226
|
+
:number => "1400",
|
227
|
+
:street => "Ave of the Americas",
|
228
|
+
:city => "New York"},
|
229
|
+
|
230
|
+
{:text => "1400 Ave of the Americas, New York",
|
231
|
+
:number => "1400",
|
232
|
+
:street => "Ave of the Americas",
|
233
|
+
:city => "New York"},
|
234
|
+
|
235
|
+
{:text => "1400 Av of the Americas, New York",
|
236
|
+
:number => "1400",
|
237
|
+
:street => "Ave of the Americas",
|
238
|
+
:city => "New York"},
|
239
|
+
|
240
|
+
{:text => "1400 Av of the Americas New York",
|
241
|
+
:number => "1400",
|
242
|
+
:street => "Ave of the Americas",
|
243
|
+
:city => "New York"},
|
244
|
+
|
245
|
+
{:text => "23 Home St, Hometown PA, 12345 US",
|
246
|
+
:number => "23",
|
247
|
+
:state => "PA",
|
248
|
+
:street => "Home St",
|
249
|
+
:city => "Hometown",
|
250
|
+
:zip => "12345"},
|
251
|
+
|
252
|
+
{:text => "23 Home St, Apt. A, Hometown PA, 12345 US",
|
253
|
+
:number => "23",
|
254
|
+
:state => "PA",
|
255
|
+
:street => "Home St",
|
256
|
+
:city => "Hometown",
|
257
|
+
:zip => "12345",
|
258
|
+
:country => "US"}
|
259
|
+
].each do |fixture|
|
260
|
+
define_method "test_parse_#{fixture[:text].gsub(/(?:\s+|[.,])/,'_')}" do
|
261
|
+
pend if fixture[:pending]
|
262
|
+
check_addr(fixture)
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
def check_addr(fixture)
|
267
|
+
text = fixture[:text]
|
268
|
+
addr = Address.new(text)
|
269
|
+
fixture.reject{|k,v| k == :text}.each do |key, val|
|
270
|
+
result = addr.send key
|
271
|
+
if result.kind_of? Array
|
272
|
+
result.map! {|str| str.downcase}
|
273
|
+
assert result.member?(val.downcase), "#{text} (#{key}) = #{result.inspect}"
|
274
|
+
else
|
275
|
+
assert_equal val, result, "#{text} (#{key}) = #{result.inspect}"
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
228
279
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Indirizzo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2011-12-14 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement: &
|
16
|
+
requirement: &70302219305600 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70302219305600
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: cover_me
|
27
|
-
requirement: &
|
27
|
+
requirement: &70302219305160 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70302219305160
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: awesome_print
|
38
|
-
requirement: &
|
38
|
+
requirement: &70302219304740 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70302219304740
|
47
47
|
description: Indirizzo is simply an extraction of the US Street Address parsing code
|
48
48
|
from Geocoder::US
|
49
49
|
email: dave@highgroove.com
|