Class: 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.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Attributes inherited from Attribute
#description, #environment_variable
Instance Method Summary collapse
- #consume(arguments) ⇒ Object
- #default_value ⇒ Object
- #help_lhs ⇒ Object
-
#initialize(name, description, options = {}) ⇒ Parameter
constructor
A new instance of Parameter.
Methods inherited from Attribute
#default_method, #help, #help_rhs, #ivar_name, #read_method, #write_method
Constructor Details
#initialize(name, description, options = {}) ⇒ Parameter
Returns a new instance of Parameter.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/clamp/parameter.rb', line 7 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 if .has_key?(:default) @default_value = [:default] end if .has_key?(:env) @environment_variable = [:env] end end |
Instance Attribute Details
#attribute_name ⇒ Object (readonly)
Returns the value of attribute attribute_name.
22 23 24 |
# File 'lib/clamp/parameter.rb', line 22 def attribute_name @attribute_name end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
22 23 24 |
# File 'lib/clamp/parameter.rb', line 22 def name @name end |
Instance Method Details
#consume(arguments) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/clamp/parameter.rb', line 28 def consume(arguments) if required? && arguments.empty? raise ArgumentError, "no value provided" end if multivalued? if arguments.length > 0 arguments.shift(arguments.length) end else arguments.shift end end |
#default_value ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/clamp/parameter.rb', line 41 def default_value if defined?(@default_value) @default_value elsif multivalued? [] end end |
#help_lhs ⇒ Object
24 25 26 |
# File 'lib/clamp/parameter.rb', line 24 def help_lhs name end |