Class: Pdi::Spoon::Options::Arg

Inherits:
Object
  • Object
show all
Defined in:
lib/pdi/spoon/options/arg.rb

Overview

This class can form Pentaho-specific command-line arguments.

Direct Known Subclasses

Param

Defined Under Namespace

Modules: Key

Constant Summary collapse

COLON =
':'
DOUBLE_QUOTE =
'"'
EMPTY =
''
HYPHEN =
'-'
SPACE =
' '

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, value = '') ⇒ Arg

Returns a new instance of Arg.

Raises:

  • (ArgumentError)


32
33
34
35
36
37
38
39
# File 'lib/pdi/spoon/options/arg.rb', line 32

def initialize(key, value = '')
  raise ArgumentError, 'key is required' if key.to_s.empty?

  @key   = Key.const_get(key.to_s.upcase.to_sym)
  @value = value.to_s

  freeze
end

Instance Attribute Details

#keyObject (readonly)

Returns the value of attribute key.



30
31
32
# File 'lib/pdi/spoon/options/arg.rb', line 30

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



30
31
32
# File 'lib/pdi/spoon/options/arg.rb', line 30

def value
  @value
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



53
54
55
56
57
# File 'lib/pdi/spoon/options/arg.rb', line 53

def ==(other)
  other.instance_of?(self.class) &&
    key == other.key &&
    value == other.value
end

#hashObject



49
50
51
# File 'lib/pdi/spoon/options/arg.rb', line 49

def hash
  [key, value].hash
end

#to_sObject



41
42
43
44
45
46
47
# File 'lib/pdi/spoon/options/arg.rb', line 41

def to_s
  separator = value.to_s.empty? ? EMPTY : COLON
  wrapper   = wrap?(key, value) ? DOUBLE_QUOTE : EMPTY
  prefix    = HYPHEN

  "#{wrapper}#{prefix}#{key}#{separator}#{value}#{wrapper}"
end