Created
July 9, 2010 12:58
-
-
Save dosire/469423 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
def to_filename(name) | |
result = name.downcase | |
result.gsub!(/\W/, ' ') # Remove any non word chars | |
result.gsub!(/\ /, '_') # Convert spaces to underscores | |
result.gsub!(/(_)$/, '') # Trim underscores at end | |
result.gsub!(/^(_)/, '') # Trim underscores at beginning | |
result.gsub!(/( )$/, '') # Trim spaces at end | |
result.gsub!(/^( )/, '') # Trim spaces at beginning | |
result = result[0..59] | |
(result.blank?) ? Time.now.to_i : result | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment