davidsouth (owner)

Revisions

gist: 126091 Download_button fork
public
Description:
Transliterate to lowercase, letters and numbers
Public Clone URL: git://gist.github.com/126091.git
Ruby
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 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