ruby - find and replace in a string for commonly used street suffix

Posted by go minimal on Stack Overflow See other posts from Stack Overflow or by go minimal
Published on 2010-06-08T04:10:17Z Indexed on 2010/06/08 4:12 UTC
Read the original article Hit count: 208

The post office actually publishes a list of commonly used street suffixes in addresses:

http://www.usps.com/ncsc/lookups/abbr_suffix.txt

I want to take this list and make a ruby function that takes a string, takes the last word ("183 main strt".split[' '].last) and if it matches any of the commonly used street suffixes ("strt"), replace it with the official Postal Service Standard Suffix ("st").

Is there a better way to approach this than a massive str.sub.sub.sub.sub.sub?

© Stack Overflow or respective owner

Related posts about ruby

Related posts about string-manipulation