Class: Clamp::Parameter
- Inherits:
-
Object
- Object
- Clamp::Parameter
- Defined in:
- lib/clamp/parameter.rb,
lib/clamp/parameter/parsing.rb,
lib/clamp/parameter/declaration.rb
Defined Under Namespace
Modules: Declaration, Parsing
Instance Attribute Summary collapse
-
#attribute_name ⇒ Object
readonly
Returns the value of attribute attribute_name.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #consume(arguments) ⇒ Object
- #help ⇒ Object
-
#initialize(name, description, options = {}) ⇒ Parameter
constructor
A new instance of Parameter.
Constructor Details
#initialize(name, description, options = {}) ⇒ Parameter
Returns a new instance of Parameter.
5 6 7 8 9 10 11 12 |
# File 'lib/clamp/parameter.rb', line 5 def initialize(name, description, = {}) @name = name @description = description infer_attribute_name_and_multiplicity if .has_key?(:attribute_name) @attribute_name = [:attribute_name].to_s end end |
Instance Attribute Details
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
14 15 16 |
# File 'lib/clamp/parameter.rb', line 14 def attribute_name @attribute_name end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
14 15 16 |
# File 'lib/clamp/parameter.rb', line 14 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/clamp/parameter.rb', line 14 def name @name end |
Instance Method Details
#consume(arguments) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/clamp/parameter.rb', line 20 def consume(arguments) if required? && arguments.empty? raise ArgumentError, "no value provided" end if multivalued? arguments.shift(arguments.length) else arguments.shift end end |
#help ⇒ Object
16 17 18 |
# File 'lib/clamp/parameter.rb', line 16 def help [name, description] end |