Created
August 7, 2009 00:22
-
-
Save klochner/163643 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 sanitize_for_filename | |
#strip the string | |
ret = self.strip | |
#blow away apostrophes | |
ret.gsub! /['`]/,"" | |
# @ --> at, & --> and | |
ret.gsub! /\s*@\s*/, " at " | |
ret.gsub! /\s*&\s*/, " and " | |
#replace all non alphanumeric, underscore or periods with underscore | |
ret.gsub! /\s*[^A-Za-z0-9\.\-]\s*/, '_' | |
#convert double underscores to single | |
ret.gsub! /_+/,"_" | |
#strip off leading/trailing underscore | |
ret.gsub! /\A[_\.]|[_\.]\z/,"" | |
ret | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment