Class: RBelly::Visitors::DotVisitor::Node

Inherits:
Struct
  • Object
show all
Defined in:
lib/rbelly/visitors/dot_visitor.rb

Constant Summary collapse

ESCAPE =
/([<>"\\])/

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fieldsObject

Returns the value of attribute fields

Returns:

  • (Object)

    the current value of fields



4
5
6
# File 'lib/rbelly/visitors/dot_visitor.rb', line 4

def fields
  @fields
end

#node_idObject

Returns the value of attribute node_id

Returns:

  • (Object)

    the current value of node_id



4
5
6
# File 'lib/rbelly/visitors/dot_visitor.rb', line 4

def node_id
  @node_id
end

Instance Method Details

#to_sObject



6
7
8
9
10
11
12
13
14
# File 'lib/rbelly/visitors/dot_visitor.rb', line 6

def to_s
  counter = 0
  label = fields.map { |f|
    s = "<f#{counter}> #{f.to_s.gsub(ESCAPE, '\\\\\1').gsub(/[\r\n]/,' ')}"
    counter += 1
    s
  }.join('|')
  "\"#{node_id}\" [\nlabel = \"#{label}\"\nshape = \"record\"\n];"
end