Class: Crew::Task::Arguments::Definition
- Inherits:
-
Object
- Object
- Crew::Task::Arguments::Definition
- Defined in:
- lib/crew/task/arguments.rb
Instance Attribute Summary collapse
-
#desc ⇒ Object
readonly
Returns the value of attribute desc.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #glob? ⇒ Boolean
-
#initialize(name, type, desc, opts) ⇒ Definition
constructor
A new instance of Definition.
- #required? ⇒ Boolean
- #value(args, opts) ⇒ Object
Constructor Details
#initialize(name, type, desc, opts) ⇒ Definition
Returns a new instance of Definition.
21 22 23 |
# File 'lib/crew/task/arguments.rb', line 21 def initialize(name, type, desc, opts) @name, @type, @desc, @opts = name, type, desc, opts end |
Instance Attribute Details
#desc ⇒ Object (readonly)
Returns the value of attribute desc.
19 20 21 |
# File 'lib/crew/task/arguments.rb', line 19 def desc @desc end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
19 20 21 |
# File 'lib/crew/task/arguments.rb', line 19 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
19 20 21 |
# File 'lib/crew/task/arguments.rb', line 19 def type @type end |
Instance Method Details
#glob? ⇒ Boolean
42 43 44 |
# File 'lib/crew/task/arguments.rb', line 42 def glob? @type == :glob end |
#required? ⇒ Boolean
38 39 40 |
# File 'lib/crew/task/arguments.rb', line 38 def required? @type == :required end |
#value(args, opts) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/crew/task/arguments.rb', line 25 def value(args, opts) val = case @type when :required then args.shift when :opt then opts.key?(@name) ? opts[@name] : @opts[:default] when :glob then args.slice!(0, args.size) else raise "unknown #{@name}" end if @opts[:type] == Integer val = Integer(val) end val end |