Class: FlowEngine::Transition
- Inherits:
-
Object
- Object
- FlowEngine::Transition
- Defined in:
- lib/flowengine/transition.rb
Overview
A single edge from one step to another, optionally guarded by a rule. Transitions are evaluated in order; the first whose rule is true determines the next step.
Instance Attribute Summary collapse
-
#rule ⇒ Rules::Base?
readonly
condition; nil means unconditional (always applies).
-
#target ⇒ Symbol
readonly
id of the step to go to when this transition applies.
Instance Method Summary collapse
-
#applies?(answers) ⇒ Boolean
Whether this transition should be taken given current answers.
-
#condition_label ⇒ String
Human-readable label for the condition (e.g. for graph export).
-
#initialize(target:, rule: nil) ⇒ Transition
constructor
A new instance of Transition.
Constructor Details
#initialize(target:, rule: nil) ⇒ Transition
14 15 16 17 18 |
# File 'lib/flowengine/transition.rb', line 14 def initialize(target:, rule: nil) @target = target @rule = rule freeze end |
Instance Attribute Details
#rule ⇒ Rules::Base? (readonly)
condition; nil means unconditional (always applies)
9 10 11 |
# File 'lib/flowengine/transition.rb', line 9 def rule @rule end |
#target ⇒ Symbol (readonly)
id of the step to go to when this transition applies
9 10 11 |
# File 'lib/flowengine/transition.rb', line 9 def target @target end |
Instance Method Details
#applies?(answers) ⇒ Boolean
Whether this transition should be taken given current answers.
31 32 33 34 35 |
# File 'lib/flowengine/transition.rb', line 31 def applies?(answers) return true if rule.nil? rule.evaluate(answers) end |
#condition_label ⇒ String
Human-readable label for the condition (e.g. for graph export).
23 24 25 |
# File 'lib/flowengine/transition.rb', line 23 def condition_label rule ? rule.to_s : "always" end |