Class: Textus::Lanes::Knowledge::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/textus/lanes/knowledge/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(manifest, cursor_store: nil) ⇒ Runner

Returns a new instance of Runner.



5
6
7
8
# File 'lib/textus/lanes/knowledge/runner.rb', line 5

def initialize(manifest, cursor_store: nil)
  @manifest = manifest
  @cursor_store = cursor_store
end

Instance Method Details

#advance(active_index: 0) ⇒ Object



28
29
30
# File 'lib/textus/lanes/knowledge/runner.rb', line 28

def advance(active_index: 0)
  current_node(active_index: active_index + 1).merge(advanced: true)
end

#advance_role(role) ⇒ Object



37
38
39
40
41
# File 'lib/textus/lanes/knowledge/runner.rb', line 37

def advance_role(role)
  idx = @cursor_store ? @cursor_store.get_loop(role)[:index] + 1 : 1
  @cursor_store&.set_loop(role, idx)
  current_node(active_index: idx).merge(advanced: true)
end

#current_node(active_index: 0) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/textus/lanes/knowledge/runner.rb', line 20

def current_node(active_index: 0)
  nodes = loop_nodes
  return nil if nodes.empty?

  idx = active_index % nodes.size
  { name: nodes[idx].key.split(".").last, index: idx, total: nodes.size }
end

#current_position(role) ⇒ Object



32
33
34
35
# File 'lib/textus/lanes/knowledge/runner.rb', line 32

def current_position(role)
  idx = @cursor_store ? @cursor_store.get_loop(role)[:index] : 0
  current_node(active_index: idx)
end

#flowObject



16
17
18
# File 'lib/textus/lanes/knowledge/runner.rb', line 16

def flow
  loop_nodes.map { |e| e.key.split(".").last }
end

#loop_nodesObject



10
11
12
13
14
# File 'lib/textus/lanes/knowledge/runner.rb', line 10

def loop_nodes
  @manifest.data.entries.select do |e|
    e.key.start_with?("knowledge.loop.") && e.key.count(".") == 2
  end
end