From 88fc445801237308447611a12251ae2781f5cb01 Mon Sep 17 00:00:00 2001 From: Sean Brewer Date: Mon, 21 Aug 2017 17:23:41 -0400 Subject: [PATCH] Fix addresses with a dirty ordinal indicator. --- lib/street_address.rb | 11 +++++++++++ test/address_test.rb | 16 ++++++++++++++++ test/street_address_test.rb | 28 ++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/lib/street_address.rb b/lib/street_address.rb index 7e74eb7..427881e 100644 --- a/lib/street_address.rb +++ b/lib/street_address.rb @@ -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 diff --git a/test/address_test.rb b/test/address_test.rb index f38f523..0e88671 100644 --- a/test/address_test.rb +++ b/test/address_test.rb @@ -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" diff --git a/test/street_address_test.rb b/test/street_address_test.rb index 5611e06..7fb5603 100644 --- a/test/street_address_test.rb +++ b/test/street_address_test.rb @@ -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',