Created
June 15, 2012 12:41
-
-
Save barelyknown/2936281 to your computer and use it in GitHub Desktop.
Standardize Company Name for Searching
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
def standardize(query) | |
query.upcase! # IbM => IBM | |
query.gsub!(/(\A|(?<=\s))(\w)\s&\s(\w)(\z|(?=\s))/,"\\2&\\3") # A & P => A&P | |
query.gsub!(/((\A|(?<=[\s\.]))\w(\z|[\s\.]+))+/, query.scan(/((\A|(?<=[\s\.]))(\w)(\z|[\s\.]+))/).collect do |match| | |
match[2] | |
end.join + " ") # I.B.M. or I. B. M. => IBM | |
query.gsub!(/\s+/," ") # MY FIRST TRUCKING CO => MY FIRST TRUCKING CO | |
query.gsub!("'","") # AL'S TOY BARN => ALS TOY BARN | |
query.strip! # " IBM " => IBM | |
query | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment