Skip to content

Instantly share code, notes, and snippets.

@davesouth
Created June 8, 2009 21:58
Show Gist options
  • Save davesouth/126091 to your computer and use it in GitHub Desktop.
Save davesouth/126091 to your computer and use it in GitHub Desktop.
Transliterate to lowercase, letters and numbers
# Based on permalink_fu by Rick Olsen
def transliterate(str)
# Escape str by transliterating to UTF-8 with Iconv
s = Iconv.iconv('ascii//ignore//translit', 'utf-8', str).to_s
# Downcase string
s.downcase!
# Remove apostrophes so isn't changes to isnt
s.gsub!(/\'/, '')
# Replace any non-letter or non-number character with a space
s.gsub!(/[^A-Za-z0-9]+/, ' ')
# Remove spaces from beginning and end of string
s.strip!
# Replace groups of spaces with single hyphen
s.gsub!(/\ +/, '-')
return s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment