Created
August 13, 2013 17:54
-
-
Save lfzawacki/6223816 to your computer and use it in GitHub Desktop.
remove accents ruby
This file contains 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 self.remove_accents(str) | |
accents = { | |
['á','à','â','ä','ã'] => 'a', | |
['Ã','Ä','Â','À'] => 'A', | |
['é','è','ê','ë'] => 'e', | |
['Ë','É','È','Ê'] => 'E', | |
['í','ì','î','ï'] => 'i', | |
['Î','Ì'] => 'I', | |
['ó','ò','ô','ö','õ'] => 'o', | |
['Õ','Ö','Ô','Ò','Ó'] => 'O', | |
['ú','ù','û','ü'] => 'u', | |
['Ú','Û','Ù','Ü'] => 'U', | |
['ç'] => 'c', ['Ç'] => 'C', | |
['ñ'] => 'n', ['Ñ'] => 'N' | |
} | |
accents.each do |ac,rep| | |
ac.each do |s| | |
str = str.gsub(s, rep) | |
end | |
end | |
str = str.gsub(/[^a-zA-Z0-9\. ]/,"") | |
str = str.gsub(/[ ]+/," ") | |
str = str.gsub(/ /,"-") | |
#str = str.downcase | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Better solution: https://stackoverflow.com/a/74029319/3634271