Class: RailroadDiagrams::Skip

Inherits:
DiagramItem show all
Defined in:
lib/railroad_diagrams/skip.rb,
sig/generated/railroad_diagrams/skip.rbs

Overview

A path with no visible item.

Examples:

Skip.new

Instance Attribute Summary

Attributes inherited from DiagramItem

#attrs, #children, #down, #height, #needs_space, #up, #width

Instance Method Summary collapse

Methods inherited from DiagramItem

#==, #add, #apply_user_attributes, #container_element?, #determine_gaps, #each_node, #hash, inherited, #inspect, #structural_state, #to_str, #walk, #wrap_string, #write_children, #write_opening_tag, #write_standalone, #write_svg

Constructor Details

#initialize(id: nil, cls: nil, attrs: {}) ⇒ Skip

Returns a new instance of Skip.

Parameters:

  • id: (Object) (defaults to: nil)
  • cls: (Object) (defaults to: nil)
  • attrs: (Object) (defaults to: {})


10
11
12
13
14
15
# File 'lib/railroad_diagrams/skip.rb', line 10

def initialize(id: nil, cls: nil, attrs: {})
  super('g', id: id, cls: cls, data_attrs: attrs)
  @width = 0
  @up = 0
  @down = 0
end

Instance Method Details

#child_nodes ⇒ Object

Returns:

  • (Object)


50
51
52
# File 'lib/railroad_diagrams/skip.rb', line 50

def child_nodes
  []
end

#format(x, y, width) ⇒ Skip

Parameters:

  • x (Numeric)
  • y (Numeric)
  • width (Numeric)

Returns:



26
27
28
29
# File 'lib/railroad_diagrams/skip.rb', line 26

def format(x, y, width)
  Path.new(x, y).right(width).add(self)
  self
end

#measure(_context) ⇒ Object

Parameters:

  • _context (Object)

Returns:

  • (Object)


37
38
39
# File 'lib/railroad_diagrams/skip.rb', line 37

def measure(_context)
  Metrics.new(width: 0, up: 0, height: 0, down: 0, needs_space: false)
end

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

Parameters:

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

Returns:

  • (Object)


41
42
43
44
# File 'lib/railroad_diagrams/skip.rb', line 41

def render_svg(context, x, y, width)
  data = Svg::PathData.new(x, y, arc_radius: context.options.arc_radius).h([0, width].max)
  Svg::Element.new('g') << Svg::Element.new('path', { 'd' => data }, self_closing: true)
end

#render_text(context) ⇒ Object

Parameters:

  • context (Object)

Returns:

  • (Object)


46
47
48
# File 'lib/railroad_diagrams/skip.rb', line 46

def render_text(context)
  TextDiagram.new(0, 0, [context.parts.fetch('line')])
end

#text_diagram ⇒ TextDiagram

Returns:

  • (TextDiagram)


32
33
34
35
# File 'lib/railroad_diagrams/skip.rb', line 32

def text_diagram
  line, = TextDiagram.get_parts(['line'])
  TextDiagram.new(0, 0, [line])
end

#to_s ⇒ String

Returns:

  • (String)


18
19
20
# File 'lib/railroad_diagrams/skip.rb', line 18

def to_s
  'Skip()'
end