street-address-rb / street-address

Detect, and dissect, US Street Addresses in strings.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Street addresses ending in "Ct" parsing inaccurately

JustinMcDonald opened this issue · comments

It is assuming "Ct" is a state, and parsing the rest of the string accordingly:

> StreetAddress::US.parse_address("122 Blueberry Ct").to_s
=> "12 2, Blueberry, CT"

Similarly, if a street address ends with a street name that is also a state, it will make the same assumption:

> StreetAddress::US.parse("122 N Virginia").to_s
=> "12 2, N, VA"

It might be more accurate to look at the number of word parts before looking for state, and/or make an exception for "Ct" in combination with number of word parts.

To be more specific, it looks like an address like "122 Blueberry Ct" is matching the formal address regex since "Ct" is matching the state list.

Same goes with the "Virginia" example above. These addresses should probably not match the formal address regex, and be treated as informal.

change line 668 to
( # special case for Connecticut (CT) (?=.*#{street_type_regexp}.*CT.*) #{street_regexp}\W+(?=.*CT) | #{street_regexp}\W+ )

This is also a problem with KY, LA, and MT
( # special case for Connecticut (CT) (?=.*#{street_type_regexp}.*(CT|KY|LA|MT).*) #{street_regexp}\W+(?=.*(CT|KY|LA|MT).) | #{street_regexp}\W+ )