Class: Smartdown::Engine::Transition

Inherits:
Object
  • Object
show all
Defined in:
lib/smartdown/engine/transition.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(state, node, input_array, options = {}) ⇒ Transition

Returns a new instance of Transition.



9
10
11
12
13
14
# File 'lib/smartdown/engine/transition.rb', line 9

def initialize(state, node, input_array, options = {})
  @state = state
  @node = node
  @inputs = input_array
  @predicate_evaluator = options[:predicate_evaluator] || PredicateEvaluator.new
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



7
8
9
# File 'lib/smartdown/engine/transition.rb', line 7

def inputs
  @inputs
end

#nodeObject (readonly)

Returns the value of attribute node.



7
8
9
# File 'lib/smartdown/engine/transition.rb', line 7

def node
  @node
end

#stateObject (readonly)

Returns the value of attribute state.



7
8
9
# File 'lib/smartdown/engine/transition.rb', line 7

def state
  @state
end

Instance Method Details

#next_nodeObject



16
17
18
19
20
# File 'lib/smartdown/engine/transition.rb', line 16

def next_node
  next_node_from_next_node_rules ||
  next_node_from_start_button ||
  raise(Smartdown::Engine::IndeterminateNextNode, "No next node rules defined for '#{node.name}'", caller)
end

#next_stateObject



22
23
24
25
26
27
# File 'lib/smartdown/engine/transition.rb', line 22

def next_state
  state_with_inputs
    .put(:path, state.get(:path) + [node.name])
    .put(:responses, state.get(:responses) + inputs)
    .put(:current_node, next_node)
end