Class: FlowEngine::Graph::MermaidExporter
- Inherits:
-
Object
- Object
- FlowEngine::Graph::MermaidExporter
- Defined in:
- lib/flowengine/graph/mermaid_exporter.rb
Overview
Exports a flow Definition to Mermaid flowchart syntax for visualization. Nodes are labeled with truncated question text; edges show condition labels when present.
Constant Summary collapse
- MAX_LABEL_LENGTH =
Maximum characters for node labels in the diagram (longer text is truncated with "...").
50
Instance Attribute Summary collapse
-
#definition ⇒ Object
readonly
Returns the value of attribute definition.
Instance Method Summary collapse
-
#export ⇒ String
Generates Mermaid flowchart TD (top-down) source.
-
#initialize(definition) ⇒ MermaidExporter
constructor
A new instance of MermaidExporter.
Constructor Details
#initialize(definition) ⇒ MermaidExporter
Returns a new instance of MermaidExporter.
14 15 16 |
# File 'lib/flowengine/graph/mermaid_exporter.rb', line 14 def initialize(definition) @definition = definition end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
11 12 13 |
# File 'lib/flowengine/graph/mermaid_exporter.rb', line 11 def definition @definition end |
Instance Method Details
#export ⇒ String
Generates Mermaid flowchart TD (top-down) source.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/flowengine/graph/mermaid_exporter.rb', line 21 def export lines = ["flowchart TD"] definition.steps.each_value do |node| lines << " #{node.id}[\"#{truncate(node.question)}\"]" node.transitions.each do |transition| label = transition.condition_label lines << if label == "always" " #{node.id} --> #{transition.target}" else " #{node.id} -->|\"#{label}\"| #{transition.target}" end end end lines.join("\n") end |