Class: RailroadDiagrams::CharClass

Inherits:
Terminal show all
Defined in:
lib/railroad_diagrams/char_class.rb,
sig/generated/railroad_diagrams/char_class.rbs

Overview

A terminal showing a character class.

Examples:

CharClass.new('[a-z]')

Instance Attribute Summary

Attributes inherited from DiagramItem

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

Instance Method Summary collapse

Methods inherited from Terminal

#add_background_rect, #add_connecting_paths, #add_text_element, #child_nodes, #format, #measure, #render_svg, #render_text, #text_diagram

Methods inherited from DiagramItem

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

Constructor Details

#initialize(text, href: nil, title: nil, cls: '', **options) ⇒ CharClass

Returns a new instance of CharClass.

Parameters:

  • text (Object)
  • href: (Object) (defaults to: nil)
  • title: (Object) (defaults to: nil)
  • cls: (Object) (defaults to: '')
  • options (Object)


9
10
11
12
# File 'lib/railroad_diagrams/char_class.rb', line 9

def initialize(text, href: nil, title: nil, cls: '', **options)
  @semantic_cls = cls
  super(text, href: href, title: title, cls: ['char-class', cls].reject(&:empty?).join(' '), **options)
end

Instance Method Details

#to_h ⇒ Object

Returns:

  • (Object)


18
19
20
21
22
23
24
25
# File 'lib/railroad_diagrams/char_class.rb', line 18

def to_h
  result = { 'type' => 'char_class', 'text' => @text }
  result['href'] = @href if @href
  result['title'] = @title if @title
  Serialization.add_attributes(result, self)
  @semantic_cls.empty? ? result.delete('cls') : result['cls'] = @semantic_cls
  result
end

#to_s ⇒ Object

Returns:

  • (Object)


14
15
16
# File 'lib/railroad_diagrams/char_class.rb', line 14

def to_s
  "CharClass(#{@text})"
end