Class: FlowEngine::Node
- Inherits:
-
Object
- Object
- FlowEngine::Node
- Defined in:
- lib/flowengine/node.rb
Overview
A single step in the flow: question metadata, input config, and conditional transitions. Used by Engine to determine the next step and by UI/export to render the step.
Instance Attribute Summary collapse
-
#fields ⇒ Array?
readonly
field names for number_matrix etc.; nil otherwise.
-
#id ⇒ Symbol
readonly
unique step identifier.
-
#max_clarifications ⇒ Integer
readonly
max follow-up rounds for :ai_intake steps (default: 0).
-
#option_labels ⇒ Hash?
readonly
key => display label mapping (nil when options are plain strings).
-
#options ⇒ Array?
readonly
option keys for select steps; nil for other types.
-
#question ⇒ String
readonly
prompt text for the step.
-
#transitions ⇒ Array<Transition>
readonly
ordered list of conditional next-step rules.
-
#type ⇒ Symbol
readonly
input type (e.g. :multi_select, :number_matrix, :ai_intake).
-
#visibility_rule ⇒ Rules::Base?
readonly
rule controlling whether this node is visible (DAG mode).
Instance Method Summary collapse
-
#ai_intake? ⇒ Boolean
True if this is an AI intake step.
-
#initialize(id:, type:, question:, decorations: nil, options: nil, fields: nil, transitions: [], visibility_rule: nil, max_clarifications: 0) ⇒ Node
constructor
A new instance of Node.
-
#next_step_id(answers) ⇒ Symbol?
Resolves the next step id from current answers by evaluating transitions in order.
-
#visible?(answers) ⇒ Boolean
Whether this node should be considered visible given current answers (for DAG/visibility).
Constructor Details
#initialize(id:, type:, question:, decorations: nil, options: nil, fields: nil, transitions: [], visibility_rule: nil, max_clarifications: 0) ⇒ Node
Returns a new instance of Node.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/flowengine/node.rb', line 29 def initialize(id:, # rubocop:disable Metrics/ParameterLists type:, question:, decorations: nil, options: nil, fields: nil, transitions: [], visibility_rule: nil, max_clarifications: 0) @id = id @type = type @question = question @decorations = decorations () @fields = fields&.freeze @transitions = transitions.freeze @visibility_rule = visibility_rule @max_clarifications = max_clarifications freeze end |
Instance Attribute Details
#fields ⇒ Array? (readonly)
field names for number_matrix etc.; nil otherwise
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def fields @fields end |
#id ⇒ Symbol (readonly)
unique step identifier
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def id @id end |
#max_clarifications ⇒ Integer (readonly)
max follow-up rounds for :ai_intake steps (default: 0)
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def max_clarifications @max_clarifications end |
#option_labels ⇒ Hash? (readonly)
key => display label mapping (nil when options are plain strings)
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def option_labels @option_labels end |
#options ⇒ Array? (readonly)
option keys for select steps; nil for other types
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def end |
#question ⇒ String (readonly)
prompt text for the step
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def question @question end |
#transitions ⇒ Array<Transition> (readonly)
ordered list of conditional next-step rules
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def transitions @transitions end |
#type ⇒ Symbol (readonly)
input type (e.g. :multi_select, :number_matrix, :ai_intake)
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def type @type end |
#visibility_rule ⇒ Rules::Base? (readonly)
rule controlling whether this node is visible (DAG mode)
16 17 18 |
# File 'lib/flowengine/node.rb', line 16 def visibility_rule @visibility_rule end |
Instance Method Details
#ai_intake? ⇒ Boolean
Returns true if this is an AI intake step.
51 52 53 |
# File 'lib/flowengine/node.rb', line 51 def ai_intake? type == :ai_intake end |
#next_step_id(answers) ⇒ Symbol?
Resolves the next step id from current answers by evaluating transitions in order.
59 60 61 62 |
# File 'lib/flowengine/node.rb', line 59 def next_step_id(answers) match = transitions.find { |t| t.applies?(answers) } match&.target end |
#visible?(answers) ⇒ Boolean
Whether this node should be considered visible given current answers (for DAG/visibility).
68 69 70 71 72 |
# File 'lib/flowengine/node.rb', line 68 def visible?(answers) return true if visibility_rule.nil? visibility_rule.evaluate(answers) end |