Skip to content

Commit 2da7cb6

Browse files
committed
Zip codes are 5 digits, not 6. (oops)
1 parent 439b659 commit 2da7cb6

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

lib/address_extractor.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def useful_address?(hash)
154154
\s+
155155
(?:[A-Za-z'.-]+\s?){0,2} (?:[A-Za-z'.-]+) # Followed by a street name
156156
)
157-
\s* ,? \s*
157+
\s* ,? \s* # a comma, optionally
158158
(
159159
(?:\d+\s+)? # a secondary unit, optionally
160160
(?:#{SECONDARY_UNIT_DESIGNATORS_REGEX})
@@ -167,10 +167,10 @@ def useful_address?(hash)
167167
\s* ,? \s* # a comma, optionally
168168
\b(#{STATE_REGEX})\b # state
169169
\s* ,? \s* # a comma, optionally
170-
(\d{6})? # a zip code, optionally
170+
(\d{5})? # a zip code, optionally
171171
)
172172
| # or, instead of city and state
173-
(\d{6})? # a lone zip code will do
173+
(\d{5})? # a lone zip code will do
174174
)
175175
/xi
176176
end

test/test_address_extractor.rb

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,20 +61,28 @@ def test_no_addresses_found
6161
via mail at:
6262
123 Goob Avenue
6363
Apt 123
64-
Nice Town CA 123456
65-
",
64+
Nice Town CA 12345",
6665
{ :street1 => "123 Foo St.", :street2 => nil, :city => "Someplace", :state => "FL", :zip => nil },
67-
{ :street1 => "123 Goob Avenue", :street2 => "Apt 123", :city => "Nice Town", :state => "CA", :zip => "123456" }
66+
{ :street1 => "123 Goob Avenue", :street2 => "Apt 123", :city => "Nice Town", :state => "CA", :zip => "12345" }
6867

69-
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, Scooby NY 123456",
70-
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => "Scooby", :state => "NY", :zip => "123456" }
68+
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, Scooby NY 12345",
69+
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => "Scooby", :state => "NY", :zip => "12345" }
7170

72-
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, Scooby, NY 123456",
73-
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => "Scooby", :state => "NY", :zip => "123456" }
71+
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, Scooby, NY 12345",
72+
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => "Scooby", :state => "NY", :zip => "12345" }
7473

75-
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, Scooby, NY, 123456",
76-
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => "Scooby", :state => "NY", :zip => "123456" }
74+
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, Scooby, NY, 12345",
75+
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => "Scooby", :state => "NY", :zip => "12345" }
7776

78-
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, 123456",
79-
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => nil, :state => nil, :zip => "123456" }
77+
test_input "Let's meet tomorrow at noon at 123 Foo Bar Street, 12345",
78+
{ :street1 => "123 Foo Bar Street", :street2 => nil, :city => nil, :state => nil, :zip => "12345" }
8079

80+
test_input "
81+
Apple Computer, Inc.
82+
1 Infinite Loop
83+
Cupertino, CA 95014",
84+
{ :street1 => "1 Infinite Loop", :street2 => nil, :city => "Cupertino", :state => "CA", :zip => "95014" }
85+
86+
test_input "Apple Computer, Inc. 1 Infinite Loop, Cupertino, CA 95014",
87+
{ :street1 => "1 Infinite Loop", :street2 => nil, :city => "Cupertino", :state => "CA", :zip => "95014" }
88+

0 commit comments

Comments
 (0)