Class: CTioga2::Commands::Instruction

Inherits:
Object
  • Object
show all
Defined in:
lib/ctioga2/commands/instruction.rb

Overview

This class represents an instruction, i.e. the execution of one Command. It is different in Command in that, for most of them, there will be arguments

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cmd, args, opts) ⇒ Instruction

Returns a new instance of Instruction.



37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ctioga2/commands/instruction.rb', line 37

def initialize(cmd, args, opts)
  if not cmd.respond_to?(:run_command)
    c = Interpreter.command(cmd)
    if ! c
      raise "Invalid command #{cmd}"
    end
    cmd = c
  end
  @command = cmd
  @arguments = args
  @options = opts
end

Instance Attribute Details

#argumentsObject

The list of its arguments, already in the correct type.



32
33
34
# File 'lib/ctioga2/commands/instruction.rb', line 32

def arguments
  @arguments
end

#commandObject

The Command



29
30
31
# File 'lib/ctioga2/commands/instruction.rb', line 29

def command
  @command
end

#optionsObject

The options, already in the correct type



35
36
37
# File 'lib/ctioga2/commands/instruction.rb', line 35

def options
  @options
end

Instance Method Details

#run(plotmaker_target) ⇒ Object

Runs this instruction again



51
52
53
# File 'lib/ctioga2/commands/instruction.rb', line 51

def run(plotmaker_target)
  @command.run_command(plotmaker_target, @arguments, @options)
end

#to_sObject



55
56
57
# File 'lib/ctioga2/commands/instruction.rb', line 55

def to_s
  "#{@command.name} #{@arguments.inspect} #{@options.inspect}"
end