Class: DTRCore::Instruction

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

Overview

Instruction class

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(instruction, inputs, assign, scope, id) ⇒ Instruction



8
9
10
11
12
13
14
# File 'lib/dtr_core/instruction.rb', line 8

def initialize(instruction, inputs, assign, scope, id)
  @instruction = instruction
  @inputs = inputs
  @assign = assign
  @scope = scope
  @id = id
end

Instance Attribute Details

#assignObject (readonly)

Returns the value of attribute assign.



6
7
8
# File 'lib/dtr_core/instruction.rb', line 6

def assign
  @assign
end

#idObject (readonly)

Returns the value of attribute id.



6
7
8
# File 'lib/dtr_core/instruction.rb', line 6

def id
  @id
end

#inputsObject (readonly)

Returns the value of attribute inputs.



6
7
8
# File 'lib/dtr_core/instruction.rb', line 6

def inputs
  @inputs
end

#instructionObject (readonly)

Returns the value of attribute instruction.



6
7
8
# File 'lib/dtr_core/instruction.rb', line 6

def instruction
  @instruction
end

#scopeObject (readonly)

Returns the value of attribute scope.



6
7
8
# File 'lib/dtr_core/instruction.rb', line 6

def scope
  @scope
end

Instance Method Details

#==(other) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/dtr_core/instruction.rb', line 16

def ==(other)
  instruction == other.instruction &&
    inputs == other.inputs &&
    assign == other.assign &&
    scope == other.scope &&
    id == other.id
end

#to_json(*_args) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/dtr_core/instruction.rb', line 31

def to_json(*_args)
  {
    instruction:,
    inputs:,
    assign:,
    scope:,
    id:
  }.to_json
end

#to_sObject



24
25
26
27
28
29
# File 'lib/dtr_core/instruction.rb', line 24

def to_s
  assignment = @assign.nil? ? '' : "assign: #{@assign}, "
  "{ id: #{id}, instruction: #{instruction}, " \
    "input: (#{inputs&.join(', ')}), " \
    "#{assignment}scope: #{scope} }"
end

#valid?Boolean



41
42
43
# File 'lib/dtr_core/instruction.rb', line 41

def valid?
  DTRCore::InstructionValidator.new(self).valid?
end