Created
June 11, 2013 11:05
-
-
Save billspat/5756072 to your computer and use it in GitHub Desktop.
simple class to shorten addresses and location descriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LocShortener | |
| @@shortening_file = 'shortening.yaml' | |
| @@shortenings = {} | |
| yamlstr = File.read(@@shortening_file) | |
| YAML.load(yamlstr).each {|k,v| @@shortenings[Regexp.new(k,Regexp::IGNORECASE)] = v} | |
| class << self | |
| def shortenings | |
| @@shortenings | |
| end | |
| def shorten!(str) | |
| str.strip! | |
| @@shortenings.each {|pattern, shortstr| str.gsub!(pattern,shortstr)} | |
| str | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| state park: S.P. | |
| provincial park: P.P. | |
| national park: N.P. | |
| state\s*forest: S.F. | |
| preserve: Pres. | |
| reserve: Res. | |
| county: Co. | |
| region: Reg. | |
| division: Div. | |
| district: Dist. | |
| parish: Par. | |
| township : Twp. | |
| lake: Lk. | |
| river: R. | |
| forest: For. | |
| island or isle: Is. | |
| park: Pk. | |
| mount(ain)?: Mt. | |
| saint: St. | |
| sainte: Ste. | |
| nature: Nat. | |
| road: Rd. | |
| highway: Hwy. | |
| parkway: Pkwy. | |
| university: U. | |
| cent((re)|(er)): Ctr. | |
| refuge: Ref. | |
| station: Sta. | |
| research station: Res. Sta. | |
| mile(s)?: mi. | |
| near. : nr. | |
| north: N | |
| north\s*west: NW | |
| west: W | |
| south\s*west: SW | |
| south: S | |
| south\s?east: SE | |
| east: E | |
| north\s?east: NE | |
| first: 1st | |
| second: 2nd | |
| third: 3rd | |
| fourth: 4th | |
| fifth: 5th | |
| sixth: 6th | |
| seventh: 7th | |
| eighth: 8th | |
| ninth: 9th | |
| one: '1' | |
| two: '2' | |
| three: '3' | |
| four: '4' | |
| five: '5' | |
| six: '6' | |
| seven: '7' | |
| eight: '8' | |
| nine: '9' | |
| ten: '10' | |
| eleven: '11' | |
| tweleve: '12' | |
| thirteen: '13' | |
| fourteen: '14' | |
| fifteen: '15' | |
| sixteen: '16' | |
| seventeen: '17' | |
| eighteen: '18' | |
| nineteen: '19' | |
| twenty: '20' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.