Skip to content

Instantly share code, notes, and snippets.

@oki
Created November 25, 2008 10:02
Show Gist options
  • Select an option

  • Save oki/28869 to your computer and use it in GitHub Desktop.

Select an option

Save oki/28869 to your computer and use it in GitHub Desktop.
def name_to_path
polish = Hash.new
polish["ą"] = "a"
polish["ć"] = "c"
polish["ę"] = "e"
polish["ł"] = "l"
polish["ń"] = "n"
polish["ó"] = "o"
polish["ś"] = "s"
polish["ż"] = "z"
polish["ź"] = "z"
polish["Ą"] = "A"
polish["Ć"] = "C"
polish["Ę"] = "E"
polish["Ł"] = "L"
polish["Ń"] = "N"
polish["Ó"] = "O"
polish["Ś"] = "S"
polish["Ż"] = "Z"
polish["Ź"] = "Z"
name.gsub(/[ąćęłńóśżźĄĆĘŁŃÓŚŻŹ]/) do
|s| polish[s]
end.downcase.gsub(/[^[:alnum:]]/,'-').gsub(/-{2,}/,'-').gsub(/^-|-$/,'')
# name.tr("ęóąśłżźćńĘÓĄŚŁŻŹĆŃ","eoaslzzcnEOASLZZCN").gsub(/[^[:alnum:]]/,'-').gsub(/-{2,}/,'-')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment