Class: Tataru::Runner
- Inherits:
-
Object
- Object
- Tataru::Runner
- Defined in:
- lib/tataru/runner.rb
Overview
thing that runs a quest
Instance Attribute Summary collapse
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
-
#oplog ⇒ Object
readonly
Returns the value of attribute oplog.
Instance Method Summary collapse
- #current_state ⇒ Object
- #ended? ⇒ Boolean
-
#initialize(instruction_list) ⇒ Runner
constructor
A new instance of Runner.
- #log_operation(instr) ⇒ Object
- #run_next ⇒ Object
Constructor Details
Instance Attribute Details
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
6 7 8 |
# File 'lib/tataru/runner.rb', line 6 def memory @memory end |
#oplog ⇒ Object (readonly)
Returns the value of attribute oplog.
6 7 8 |
# File 'lib/tataru/runner.rb', line 6 def oplog @oplog end |
Instance Method Details
#current_state ⇒ Object
46 |
# File 'lib/tataru/runner.rb', line 46 def current_state; end |
#ended? ⇒ Boolean
14 15 16 17 18 |
# File 'lib/tataru/runner.rb', line 14 def ended? @memory.program_counter >= @instruction_list.length || !@memory.error.nil? || @memory.end end |
#log_operation(instr) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/tataru/runner.rb', line 20 def log_operation(instr) return unless instr.is_a? Instructions::ResourceInstruction oplog << { operation: instr.class.name.underscore .sub(%r{^tataru/instructions/}, '') .sub(/_instruction$/, '').upcase.to_s, resource: (memory.hash[:temp][:resource_name]).to_s } end |
#run_next ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/tataru/runner.rb', line 31 def run_next return if ended? instr = @instruction_list[@memory.program_counter] log_operation(instr) instr.execute(@memory) @memory.program_counter += 1 rescue RuntimeError => e @memory.error = e rescue StandardError => e @memory.error = e end |