Class: Crew::Task::Arguments::Definition

Inherits:
Object
  • Object
show all
Defined in:
lib/crew/task/arguments.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#descObject (readonly)

Returns the value of attribute desc.



19
20
21
# File 'lib/crew/task/arguments.rb', line 19

def desc
  @desc
end

#nameObject (readonly)

Returns the value of attribute name.



19
20
21
# File 'lib/crew/task/arguments.rb', line 19

def name
  @name
end

#typeObject (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

Returns:

  • (Boolean)


42
43
44
# File 'lib/crew/task/arguments.rb', line 42

def glob?
  @type == :glob
end

#required?Boolean

Returns:

  • (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