Class: Furnace::Graphviz
- Inherits:
-
Object
- Object
- Furnace::Graphviz
- Defined in:
- lib/furnace/graphviz.rb
Instance Method Summary collapse
- #edge(from, to, label = "", options = {}) ⇒ Object
- #graphviz_options(options) ⇒ Object
-
#initialize {|_self| ... } ⇒ Graphviz
constructor
A new instance of Graphviz.
- #node(name, content, options = {}) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize {|_self| ... } ⇒ Graphviz
Returns a new instance of Graphviz.
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="", ={}) = .merge({ label: label.inspect }) @code << %Q{"#{from.inspect}" -> "#{to.inspect}" #{()};\n} end |
#graphviz_options(options) ⇒ Object
46 47 48 |
# File 'lib/furnace/graphviz.rb', line 46 def () "[#{.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, ={}) content.gsub!("&", "&") content.gsub!(">", ">") content.gsub!("<", "<") content.gsub!(/\*\*(.+?)\*\*/, '<b>\1</b>') content = content.lines.map { |l| %Q{<tr><td align="left">#{l}</td></tr>} }.join if content.empty? label = "<<empty>>" else label = "<<table border=\"0\">#{content}</table>>" end = .merge({ shape: 'box', label: label }) @code << %Q{"#{name.inspect}" #{()};\n} end |
#to_s ⇒ Object
42 43 44 |
# File 'lib/furnace/graphviz.rb', line 42 def to_s @code end |