Module: BatchExperiment::FnameSanitizer
- Defined in:
- lib/batch_experiment.rb
Overview
The default callable object used by Comm2FnameConverter to convert a command into a filename. Comm2FnameConverter don’t create a sanitized filename from the command string (it uses its first argument to do this, whose default is FnameSanitizer). Note that this is a pure function, so if the same command appears more than one time, it will get the same name, it’s Comm2FnameConverter that gives multiple instances of the same command different names (by suffixing with numbers).
Class Method Summary collapse
-
.call(command) ⇒ String
Returns a copy of the argument where each sequence of non-alphanumeric characters were changed to one single underscore (‘_’), remove trailing underscores at the beggining and the end of the string.
Class Method Details
.call(command) ⇒ String
Returns a copy of the argument where each sequence of non-alphanumeric characters were changed to one single underscore (‘_’), remove trailing underscores at the beggining and the end of the string.
22 23 24 25 26 27 28 29 |
# File 'lib/batch_experiment.rb', line 22 def self.call(command) fname = command.strip fname.gsub!(/[^[:alnum:]]/, '_') fname.gsub!(/_+/, '_') fname.gsub!(/^_/, '') fname.gsub!(/_$/, '') fname end |