Class: Inquirex::Graph::MermaidExporter
- Inherits:
-
Object
- Object
- Inquirex::Graph::MermaidExporter
- Defined in:
- lib/inquirex/graph/mermaid_exporter.rb
Overview
Exports a flow Definition to Mermaid flowchart syntax for visualization. Node labels show verb + truncated question/text; edges show condition labels.
Constant Summary collapse
- MAX_LABEL_LENGTH =
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.
13 14 15 |
# File 'lib/inquirex/graph/mermaid_exporter.rb', line 13 def initialize(definition) @definition = definition end |
Instance Attribute Details
#definition ⇒ Object (readonly)
Returns the value of attribute definition.
10 11 12 |
# File 'lib/inquirex/graph/mermaid_exporter.rb', line 10 def definition @definition end |
Instance Method Details
#export ⇒ String
Generates Mermaid flowchart TD (top-down) source.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/inquirex/graph/mermaid_exporter.rb', line 20 def export lines = ["flowchart TD"] @definition.steps.each_value do |node| lines << " #{node.id}[\"#{node_label(node)}\"]" 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 |