Class: Graphviz::Diagram::RecordLabel

Inherits:
Object
  • Object
show all
Defined in:
lib/graphviz/diagram/record_label.rb

Overview

Provide an interface for create Graphviz record type labels

Instance Method Summary collapse

Constructor Details

#initializeRecordLabel

Returns a new instance of RecordLabel.



9
10
11
# File 'lib/graphviz/diagram/record_label.rb', line 9

def initialize
  @rows = [] # list of Strings
end

Instance Method Details

#add_row(string, opts = {}) ⇒ Object

rubocop:disable MethodLength



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/graphviz/diagram/record_label.rb', line 14

def add_row(string, opts = {})
  str = quote(string).chomp
  str = format '<%s> %s', opts[:field_id], str if opts[:field_id]
  if opts[:align]
    case opts[:align].to_sym
    when :left then @rows << str + ' \l'
    when :right then @rows << str + ' \r'
    else
      fail "unsupported align #{opts[:align]}"
    end
  else
    @rows << str + "\n"
  end
end

#add_separatorObject



29
30
31
# File 'lib/graphviz/diagram/record_label.rb', line 29

def add_separator
  @rows << '|'
end

#to_sObject



33
34
35
# File 'lib/graphviz/diagram/record_label.rb', line 33

def to_s
  @rows.join('').chomp.gsub("\n|", '|')
end