Module: RailroadDiagrams::ExpandedNode

Included in:
Except, Repeat, SeparatedList
Defined in:
lib/railroad_diagrams/expanded_node.rb,
sig/generated/railroad_diagrams/expanded_node.rbs

Overview

Nodes with their own meaning but the geometry of existing nodes.

Instance Method Summary collapse

Instance Method Details

#adopt_expansion(node) ⇒ Object

Parameters:

  • node (Object)

Returns:

  • (Object)


39
40
41
42
43
44
45
46
# File 'lib/railroad_diagrams/expanded_node.rb', line 39

def adopt_expansion(node)
  @expanded = node
  @width = node.width
  @up = node.up
  @height = node.height
  @down = node.down
  @needs_space = node.needs_space
end

#expanded(_context = nil) ⇒ Object

Parameters:

  • _context (Object) (defaults to: nil)

Returns:

  • (Object)


35
36
37
# File 'lib/railroad_diagrams/expanded_node.rb', line 35

def expanded(_context = nil)
  @expanded
end

#format(x, y, width) ⇒ Object

Parameters:

  • x (Object)
  • y (Object)
  • width (Object)

Returns:

  • (Object)


7
8
9
10
# File 'lib/railroad_diagrams/expanded_node.rb', line 7

def format(x, y, width)
  expanded.format(x, y, width).add(self)
  self
end

#measure(context) ⇒ Object

Parameters:

  • context (Object)

Returns:

  • (Object)


16
17
18
# File 'lib/railroad_diagrams/expanded_node.rb', line 16

def measure(context)
  context.metrics(expanded(context))
end

#render_svg(context, x, y, width) ⇒ Object

Parameters:

  • context (Object)
  • x (Object)
  • y (Object)
  • width (Object)

Returns:

  • (Object)


20
21
22
# File 'lib/railroad_diagrams/expanded_node.rb', line 20

def render_svg(context, x, y, width)
  Svg::Element.new('g', @attrs.dup) << expanded(context).render_svg(context, x, y, width)
end

#render_text(context) ⇒ Object

Parameters:

  • context (Object)

Returns:

  • (Object)


24
25
26
# File 'lib/railroad_diagrams/expanded_node.rb', line 24

def render_text(context)
  expanded(context).render_text(context)
end

#text_diagram ⇒ Object

Returns:

  • (Object)


12
13
14
# File 'lib/railroad_diagrams/expanded_node.rb', line 12

def text_diagram
  expanded.text_diagram
end

#walk(callback) ⇒ Object

Parameters:

  • callback (Object)

Returns:

  • (Object)


28
29
30
31
# File 'lib/railroad_diagrams/expanded_node.rb', line 28

def walk(callback)
  callback.call(self)
  child_nodes.each { |child| child.walk(callback) }
end