Class: SyntaxTree::Mermaid::Node

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

Overview

This class represents a node in a flowchart. Unlike the Link class, it can be used directly. It is the return value of the #node method, and is meant to be passed around to #link methods to create links between nodes.

Constant Summary collapse

SHAPES =
%i[circle rectangle rounded stadium].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, label, shape) ⇒ Node

Returns a new instance of Node.



126
127
128
129
130
131
132
# File 'lib/syntax_tree/mermaid.rb', line 126

def initialize(id, label, shape)
  raise unless SHAPES.include?(shape)

  @id = id
  @label = label
  @shape = shape
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



124
125
126
# File 'lib/syntax_tree/mermaid.rb', line 124

def id
  @id
end

#labelObject (readonly)

Returns the value of attribute label.



124
125
126
# File 'lib/syntax_tree/mermaid.rb', line 124

def label
  @label
end

#shapeObject (readonly)

Returns the value of attribute shape.



124
125
126
# File 'lib/syntax_tree/mermaid.rb', line 124

def shape
  @shape
end

Instance Method Details

#renderObject



134
135
136
137
# File 'lib/syntax_tree/mermaid.rb', line 134

def render
  left_bound, right_bound = bounds
  "#{id}#{left_bound}#{Mermaid.escape(label)}#{right_bound}"
end