Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix addresses with a dirty ordinal indicator. #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/street_address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,17 @@ def to_address(input, args)
}
end

# Fix cases with a dirty ordinal indicator:
# Sometimes parcel data will have addresses like
# "1 1ST ST"
# as
# "1 1 ST ST"
if( input['street'] )
input['street'].gsub!(/\A(\d+\s+st|\d+\s+nd|\d+\s+rd|\d+\s+th)\z/i) { |match|
input['street'].gsub(/\s+/, "")
}
end

%w(street street_type street2 street_type2 city unit_prefix).each do |k|
input[k] = input[k].split.map(&:capitalize).join(' ') if input[k]
end
Expand Down
16 changes: 16 additions & 0 deletions test/address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,22 @@ class AddressTest < MiniTest::Test
:line1 => "1 First St",
:line2 => "East San Jose, CA"
},
"1 1 ST St, e San Jose CA" => { # Addresses with a dirty ordinal indicator
:line1 => "1 1st St",
:line2 => "East San Jose, CA"
},
"1 2 ND St, e San Jose CA" => {
:line1 => "1 2nd St",
:line2 => "East San Jose, CA"
},
"1 3 RD St, e San Jose CA" => {
:line1 => "1 3rd St",
:line2 => "East San Jose, CA"
},
"1 4 TH St, e San Jose CA" => {
:line1 => "1 4th St",
:line2 => "East San Jose, CA"
},
"lt42 99 Some Road, Some City LA" => {
:line1 => "99 Some Rd Lt 42",
:line2 => "Some City, LA"
Expand Down
28 changes: 28 additions & 0 deletions test/street_address_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,34 @@ class StreetAddressUsTest < MiniTest::Test
:city => 'East San Jose',
:street_type => 'St',
},
"1 1 ST St, e San Jose CA" => { # Addresses with a dirty ordinal indicator
:number => '1',
:street => '1st',
:state => 'CA',
:city => 'East San Jose',
:street_type => 'St',
},
"1 2 ND St, e San Jose CA" => {
:number => '1',
:street => '2nd',
:state => 'CA',
:city => 'East San Jose',
:street_type => 'St',
},
"1 3 RD St, e San Jose CA" => {
:number => '1',
:street => '3rd',
:state => 'CA',
:city => 'East San Jose',
:street_type => 'St',
},
"1 4 TH St, e San Jose CA" => {
:number => '1',
:street => '4th',
:state => 'CA',
:city => 'East San Jose',
:street_type => 'St',
},
"123 Maple Rochester, New York" => { # space in state name
:street_type => nil,
:number => '123',
Expand Down