Class: Furnace::Graphviz

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

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Graphviz

Returns a new instance of Graphviz.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
9
10
11
12
# File 'lib/furnace/graphviz.rb', line 4

def initialize
  @code = "digraph {\n"
  @code << "node [labeljust=l,nojustify=true,fontname=monospace];"
  @code << "rankdir=TB;\n"

  yield self

  @code << "}"
end

Instance Method Details

#edge(from, to, label = "", options = {}) ⇒ Object



35
36
37
38
39
40
# File 'lib/furnace/graphviz.rb', line 35

def edge(from, to, label="", options={})
  options = options.merge({
    label: label.inspect
  })
  @code << %Q{#{from.inspect} -> #{to.inspect} #{graphviz_options(options)};\n}
end

#graphviz_options(options) ⇒ Object



46
47
48
# File 'lib/furnace/graphviz.rb', line 46

def graphviz_options(options)
  "[#{options.map { |k,v| "#{k}=#{v}" }.join(",")}]"
end

#node(name, content, options = {}) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/furnace/graphviz.rb', line 14

def node(name, content, options={})
  content.gsub!("&", "&amp;")
  content.gsub!(">", "&gt;")
  content.gsub!("<", "&lt;")
  content.gsub!(/\*\*(.+?)\*\*/, '<b>\1</b>')
  content = content.lines.map { |l| %Q{<tr><td align="left">#{l}</td></tr>} }.join

  if content.empty?
    label = "<&lt;empty&gt;>"
  else
    label = "<<table border=\"0\">#{content}</table>>"
  end

  options = options.merge({
    shape: 'box',
    label: label
  })

  @code << %Q{#{name.inspect} #{graphviz_options(options)};\n}
end

#to_sObject



42
43
44
# File 'lib/furnace/graphviz.rb', line 42

def to_s
  @code
end