Class: Toys::Definition::Arg

Inherits:
Object
  • Object
show all
Defined in:
lib/toys/definition/arg.rb

Overview

Representation of a formal positional argument

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#acceptObject

Returns the acceptor, which may be nil.



70
71
72
# File 'lib/toys/definition/arg.rb', line 70

def accept
  @accept
end

#defaultObject (readonly)

Returns the default value, which may be nil.



76
77
78
# File 'lib/toys/definition/arg.rb', line 76

def default
  @default
end

#descToys::Utils::WrappableString

Returns the short description string.



82
83
84
# File 'lib/toys/definition/arg.rb', line 82

def desc
  @desc
end

#display_nameString

Returns the displayable name.



94
95
96
# File 'lib/toys/definition/arg.rb', line 94

def display_name
  @display_name
end

#keySymbol (readonly)

Returns the key.



58
59
60
# File 'lib/toys/definition/arg.rb', line 58

def key
  @key
end

#long_descArray<Toys::Utils::WrappableString>

Returns the long description strings as an array.



88
89
90
# File 'lib/toys/definition/arg.rb', line 88

def long_desc
  @long_desc
end

#type:required, ... (readonly)

Type of this argument.



64
65
66
# File 'lib/toys/definition/arg.rb', line 64

def type
  @type
end

Instance Method Details

#process_value(input) ⇒ Object

Process the given value through the acceptor. May raise an exception if the acceptor rejected the input.



103
104
105
106
107
108
109
110
111
# File 'lib/toys/definition/arg.rb', line 103

def process_value(input)
  return input unless accept
  result = input
  optparse = ::OptionParser.new
  optparse.accept(accept) if accept.is_a?(Acceptor)
  optparse.on("--abc VALUE", accept) { |v| result = v }
  optparse.parse(["--abc", input])
  result
end