Class: Toys::Definition::Arg
- Inherits:
-
Object
- Object
- Toys::Definition::Arg
- Defined in:
- lib/toys/definition/arg.rb
Overview
Representation of a formal positional argument
Instance Attribute Summary collapse
-
#accept ⇒ Object
Returns the acceptor, which may be
nil. -
#default ⇒ Object
readonly
Returns the default value, which may be
nil. -
#desc ⇒ Toys::Utils::WrappableString
Returns the short description string.
-
#display_name ⇒ String
Returns the displayable name.
-
#key ⇒ Symbol
readonly
Returns the key.
-
#long_desc ⇒ Array<Toys::Utils::WrappableString>
Returns the long description strings as an array.
-
#type ⇒ :required, ...
readonly
Type of this argument.
Instance Method Summary collapse
-
#process_value(input) ⇒ Object
Process the given value through the acceptor.
Instance Attribute Details
#accept ⇒ Object
Returns the acceptor, which may be nil.
70 71 72 |
# File 'lib/toys/definition/arg.rb', line 70 def accept @accept end |
#default ⇒ Object (readonly)
Returns the default value, which may be nil.
76 77 78 |
# File 'lib/toys/definition/arg.rb', line 76 def default @default end |
#desc ⇒ Toys::Utils::WrappableString
Returns the short description string.
82 83 84 |
# File 'lib/toys/definition/arg.rb', line 82 def desc @desc end |
#display_name ⇒ String
Returns the displayable name.
94 95 96 |
# File 'lib/toys/definition/arg.rb', line 94 def display_name @display_name end |
#key ⇒ Symbol (readonly)
Returns the key.
58 59 60 |
# File 'lib/toys/definition/arg.rb', line 58 def key @key end |
#long_desc ⇒ Array<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 |