class Graphviz::Diagram::RecordLabel
Provide an interface for create Graphviz
record type labels
Public Class Methods
new()
click to toggle source
# File lib/graphviz/diagram/record_label.rb, line 9 def initialize @rows = [] # list of Strings end
Public Instance Methods
add_row(string, opts = {})
click to toggle source
rubocop:disable MethodLength
# 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_separator()
click to toggle source
# File lib/graphviz/diagram/record_label.rb, line 29 def add_separator @rows << '|' end
to_s()
click to toggle source
# File lib/graphviz/diagram/record_label.rb, line 33 def to_s @rows.join('').chomp.gsub("\n|", '|') end
Private Instance Methods
quote(label)
click to toggle source
# File lib/graphviz/diagram/record_label.rb, line 39 def quote(label) label.gsub(/\[\]\{\}\(\)\s/) { |w| '\\' + w } end