Skip to content

Instantly share code, notes, and snippets.

@angelbotto
Last active December 10, 2015 14:49
Show Gist options
  • Save angelbotto/4449938 to your computer and use it in GitHub Desktop.
Save angelbotto/4449938 to your computer and use it in GitHub Desktop.
Creando el username perfecto, un pequeño metodo que ayuda a remplazar y eliminar caracteres extraños para crear un username perfecto :) :s si tiene ideas de como poder mejorarlo agradeceria enormemente :)
def perfectUsername(string)
string = string.tr(' ','-')
string = string.tr('áàäâªÁÀÂÄéèëêÉÈÊËíìïîÍÌÏÎóòöôÓÒÖÔ','aaaaaAAAAeeeeEEEEiiiiIIIIooooOOOOúùüûÚÙÛÜuuuuUUUUñÑçÇnNcC')
string = string.gsub(/[^0-9A-Za-z]/, '')
end
@username = "ÁngelÑelis Bo##o@%☻.com_"
puts @username
#ÁngelÑelis Bo##o@%☻.com_
puts perfectUsername(@username)
#AngelelisBoocom
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment