Created
October 27, 2009 16:49
-
-
Save herval/219717 to your computer and use it in GitHub Desktop.
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
# String extension to remove non-ascii/graphic accent characters | |
# pt-BR: métodos para remover acentos (e espaços) de String | |
require 'iconv' | |
class String | |
# São José do Poço -> Sao Jose do Poco | |
def remove_non_ascii | |
Iconv.iconv("ASCII//IGNORE//TRANSLIT", "UTF-8", self).join.gsub(/[^a-z._0-9 -]/i, "").tr(".", "_") | |
end | |
# São José do Poço -> sao-jose-do-poco | |
# perfect for slugs! | |
def remove_non_ascii_and_spaces | |
# very compact, heh!? | |
remove_non_ascii.gsub(/(\s+)/, "_").dasherize.downcase | |
end | |
# São José do Poço -> saojosedopoco | |
def remove_non_ascii_and_spaces_and_dashes | |
remove_non_ascii.gsub(/(\s+)/, "").downcase | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment