Class: Tataru::Taru

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

Overview

Entry class

Instance Method Summary collapse

Constructor Details

#initialize(rtp, current_state = {}, &block) ⇒ Taru

Returns a new instance of Taru.



28
29
30
31
32
33
34
35
# File 'lib/tataru.rb', line 28

def initialize(rtp, current_state = {}, &block)
  @rtp = rtp
  @current_state = current_state
  @quest = Tataru::Quest.new(rtp, current_state)
  @quest.construct(&block)
  @ih = Tataru::InstructionHash.new(@quest.instr_hash)
  @runner = Tataru::Runner.new(@ih.instruction_list)
end

Instance Method Details

#errorObject



46
47
48
# File 'lib/tataru.rb', line 46

def error
  @runner.memory.error
end

#extract_state(key, value) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/tataru.rb', line 56

def extract_state(key, value)
  if key.start_with? '_deletable_'
    original_key = key.sub(/^_deletable_/, '')
    [key, {
      name: value,
      desc: @current_state[original_key][:desc],
      dependencies: @current_state[original_key][:dependencies]
    }]
  else
    [key, {
      name: value,
      desc: @quest.dsl.resources[key].desc.class.name,
      dependencies: @quest.dsl.dep_graph[key]
    }]
  end
end

#oplogObject



42
43
44
# File 'lib/tataru.rb', line 42

def oplog
  @runner.oplog
end

#stateObject



50
51
52
53
54
# File 'lib/tataru.rb', line 50

def state
  @runner.memory.hash[:remote_ids].map do |k, v|
    extract_state(k, v)
  end.to_h
end

#stepObject



37
38
39
40
# File 'lib/tataru.rb', line 37

def step
  @runner.run_next
  !@runner.ended?
end