| Class | String |
| In: |
lib/noosfero/core_ext/string.rb
|
| Parent: | Object |
| TRANSLITERATIONS | = | { [ 'Á', 'À', 'À', 'Â', 'Ã', 'Ä' ] => 'A', [ 'á', 'à', 'à', 'â', 'ã', 'ä', 'ª' ] => 'a', [ 'É', 'È', 'Ê', 'Ë' ] => 'E', [ 'é', 'è', 'ê', 'ë' ] => 'e', [ 'Í', 'Ì', 'Î', 'Ï' ] => 'I', [ 'í', 'ì', 'î', 'ï' ] => 'i', [ 'Ó', 'Ò', 'Ô', 'Ö', 'Õ', 'º' ] => 'O', [ 'ó', 'ò', 'ô', 'ö', 'õ', 'º' ] => 'o', [ 'Ú', 'Ù', 'Û', 'Ü' ] => 'U', [ 'ú', 'ù', 'û', 'ü' ] => 'u', [ 'Ç' ] => 'C', [ 'ç' ] => 'c', [ 'Ñ' ] => 'N', [ 'ñ' ] => 'n', [ 'Ÿ' ] => 'Y', [ 'ÿ' ] => 'y', } |
# File lib/noosfero/core_ext/string.rb, line 39
39: def to_slug
40: transliterate.downcase.gsub(/^\d+/,'').gsub( /[^a-z0-9~\s:;+=_.-]/, '').gsub(/[\s:;+=_-]+/, '-').gsub(/-$/, '').gsub(/^-/, '').to_s
41: end
transliterate a string (assumed to contain UTF-8 data) into ASCII by replacing non-ascii characters to their ASCII.
The transliteration is, of course, lossy, and its performance is poor. Don‘t abuse this method.
# File lib/noosfero/core_ext/string.rb, line 28
28: def transliterate
29:
30: new = self.clone
31: TRANSLITERATIONS.each { |from,to|
32: from.each { |seq|
33: new.gsub!(seq, to)
34: }
35: }
36: new
37: end