Skip to content

Instantly share code, notes, and snippets.

@billspat
Created June 11, 2013 11:05
Show Gist options
  • Save billspat/5756072 to your computer and use it in GitHub Desktop.
Save billspat/5756072 to your computer and use it in GitHub Desktop.
simple class to shorten addresses and location descriptions
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
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'
@billspat
Copy link
Author

billspat commented Jun 11, 2013

LocShortener.shorten!('Ingham County Mount Lake State Park, 3 Miles East of First Street')
        # => "Ingham Co. Mt. Lk. S.P., 3 mi. E of 1st Street"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment