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

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.

Parameters:

  • command (String)

    A command to be sanitized.

Returns:

  • (String)

    The sanitized command.



33
34
35
36
37
38
39
40
# File 'lib/batch_experiment.rb', line 33

def self.call(command)
  fname = command.strip
  fname.gsub!(/[^[:alnum:]]/, '_')
  fname.gsub!(/_+/, '_')
  fname.gsub!(/^_/, '')
  fname.gsub!(/_$/, '')
  fname
end