Class: DeepTest::Option

Inherits:
Object
  • Object
show all
Defined in:
lib/deep_test/option.rb

Defined Under Namespace

Modules: Array, Hash, Integer, String, Symbol

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type, default) ⇒ Option

Returns a new instance of Option.



5
6
7
# File 'lib/deep_test/option.rb', line 5

def initialize(name, type, default)
  @name, @type, @default = name, type, default
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



3
4
5
# File 'lib/deep_test/option.rb', line 3

def default
  @default
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/deep_test/option.rb', line 3

def name
  @name
end

Instance Method Details

#from_command_line(command_line) ⇒ Object



9
10
11
12
# File 'lib/deep_test/option.rb', line 9

def from_command_line(command_line)
  command_line =~ /--#{name} (\S+)(\s|$)/
  @type.from_string($1) if $1
end

#to_command_line(value) ⇒ Object



14
15
16
# File 'lib/deep_test/option.rb', line 14

def to_command_line(value)
  "--#{name} #{@type.to_string(value)}" if value && value != default
end