Class: Kommand::Scripts::Argument
- Inherits:
-
Object
- Object
- Kommand::Scripts::Argument
- Defined in:
- lib/kommand/scripts/argument.rb
Instance Attribute Summary collapse
-
#summary ⇒ Object
readonly
Returns the value of attribute summary.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
-
#value ⇒ Object
Returns the value of attribute value.
Instance Method Summary collapse
- #key ⇒ Object
- #keys ⇒ Object
- #name ⇒ Object
-
#unnamed? ⇒ Boolean
is this an unnamed argument?.
-
#valid? ⇒ Boolean
is this argument valid?.
-
#validate? ⇒ Boolean
should this argument validate?.
Instance Attribute Details
#summary ⇒ Object (readonly)
Returns the value of attribute summary.
4 5 6 |
# File 'lib/kommand/scripts/argument.rb', line 4 def summary @summary end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
4 5 6 |
# File 'lib/kommand/scripts/argument.rb', line 4 def valid @valid end |
#value ⇒ Object
Returns the value of attribute value.
4 5 6 |
# File 'lib/kommand/scripts/argument.rb', line 4 def value @value end |
Instance Method Details
#key ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/kommand/scripts/argument.rb', line 11 def key if unnamed? value else @keys.is_a?(Array) ? @keys[0] : @keys end end |
#keys ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/kommand/scripts/argument.rb', line 19 def keys if unnamed? [value] else @keys.is_a?(Array) ? @keys : [@keys] end end |
#name ⇒ Object
27 28 29 |
# File 'lib/kommand/scripts/argument.rb', line 27 def name keys.sort { |a,b| a.length <=> b.length }.last.gsub(/^--/, '') end |
#unnamed? ⇒ Boolean
is this an unnamed argument?
32 33 34 |
# File 'lib/kommand/scripts/argument.rb', line 32 def unnamed? @keys == nil end |
#valid? ⇒ Boolean
is this argument valid?
37 38 39 |
# File 'lib/kommand/scripts/argument.rb', line 37 def valid? !((validate? && !@valid.include?(val)) && (!val.nil? && !val.empty?)) end |
#validate? ⇒ Boolean
should this argument validate?
42 43 44 |
# File 'lib/kommand/scripts/argument.rb', line 42 def validate? !@valid.nil? end |