Class: Gnu

Inherits:
CommandParser show all
Defined in:
lib/runnable/gnu.rb

Overview

Parse the parameter hash using the GNU standard.

Instance Method Summary collapse

Methods inherited from CommandParser

#add_param, #initialize

Constructor Details

This class inherits a constructor from CommandParser

Instance Method Details

#parseArray

This method convert a hash in an array of strings ready to be passed to a command that uses GNU style to parse command line parameters.

Returns:

  • (Array)

    Gnu-style parsed params in a string array.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/runnable/gnu.rb', line 27

def parse
  @params.collect do |param, value|
    # We assume that an one character words is preceed by one
    # lead and two or more characters words are preceed by two 
    # leads
    option = ( param.length == 1 ? "-#{param}" : "--#{param}" )

    # In case the param have parameter we use the correct assignation
    #   -Param followed by value (whitout whitespace) to one character params
    #   -Param followed by '=' and value to more than one character params
    if( value != nil )
      option.concat( param.length == 1 ? "#{value}" : "=#{value}" )
    end

    option
  end
end