Class: SyntaxTree::Mermaid::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/syntax_tree/mermaid.rb

Overview

This class represents a link between two nodes in a flowchart. It is not meant to be interacted with directly, but rather used as a data structure by the FlowChart class.

Constant Summary collapse

TYPES =
%i[directed dotted].freeze
COLORS =
%i[green red].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from, to, label, type, color) ⇒ Link

Returns a new instance of Link.



84
85
86
87
88
89
90
91
92
93
# File 'lib/syntax_tree/mermaid.rb', line 84

def initialize(from, to, label, type, color)
  raise unless TYPES.include?(type)
  raise if color && !COLORS.include?(color)

  @from = from
  @to = to
  @label = label
  @type = type
  @color = color
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



82
83
84
# File 'lib/syntax_tree/mermaid.rb', line 82

def color
  @color
end

#fromObject (readonly)

Returns the value of attribute from.



82
83
84
# File 'lib/syntax_tree/mermaid.rb', line 82

def from
  @from
end

#labelObject (readonly)

Returns the value of attribute label.



82
83
84
# File 'lib/syntax_tree/mermaid.rb', line 82

def label
  @label
end

#toObject (readonly)

Returns the value of attribute to.



82
83
84
# File 'lib/syntax_tree/mermaid.rb', line 82

def to
  @to
end

#typeObject (readonly)

Returns the value of attribute type.



82
83
84
# File 'lib/syntax_tree/mermaid.rb', line 82

def type
  @type
end

Instance Method Details

#renderObject



95
96
97
98
99
100
101
102
103
104
# File 'lib/syntax_tree/mermaid.rb', line 95

def render
  left_side, right_side, full_side = sides

  if label
    escaped = Mermaid.escape(label)
    "#{from.id} #{left_side} #{escaped} #{right_side} #{to.id}"
  else
    "#{from.id} #{full_side} #{to.id}"
  end
end