Class: CooCoo::Dot::Writer
Instance Method Summary collapse
- #indent(size) ⇒ Object
-
#initialize ⇒ Writer
constructor
A new instance of Writer.
- #start_block(kind, depth) ⇒ Object
- #write(graph, io) ⇒ Object
- #write_edges(edges, depth) ⇒ Object
- #write_graph(g, depth = 0) ⇒ Object
- #write_graph_options(graph, depth) ⇒ Object
- #write_nodes(nodes, depth) ⇒ Object
- #write_options(options) ⇒ Object
Constructor Details
#initialize ⇒ Writer
Returns a new instance of Writer.
71 72 |
# File 'lib/coo-coo/dot.rb', line 71 def initialize end |
Instance Method Details
#indent(size) ⇒ Object
92 93 94 |
# File 'lib/coo-coo/dot.rb', line 92 def indent(size) " " * size end |
#start_block(kind, depth) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/coo-coo/dot.rb', line 102 def start_block(kind, depth) [ indent(depth) + "#{kind} {", *yield(depth + 1), indent(depth) + "}" ] end |
#write(graph, io) ⇒ Object
74 75 76 77 |
# File 'lib/coo-coo/dot.rb', line 74 def write(graph, io) io.write(write_graph(graph).join("\n")) self end |
#write_edges(edges, depth) ⇒ Object
115 116 117 118 119 120 |
# File 'lib/coo-coo/dot.rb', line 115 def write_edges(edges, depth) edges.collect do |edge| nodes = edge.nodes.join(" -> ") indent(depth) + "#{nodes}[#{(edge.)}];" end end |
#write_graph(g, depth = 0) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/coo-coo/dot.rb', line 79 def write_graph(g, depth = 0) start_block("#{g.kind}", depth) do |d| lines = [] lines += (g, d) g.blocks.each do |kid| lines += write_graph(kid, d) end lines += write_nodes(g.nodes, d) lines += write_edges(g.edges, d) lines end end |
#write_graph_options(graph, depth) ⇒ Object
96 97 98 99 100 |
# File 'lib/coo-coo/dot.rb', line 96 def (graph, depth) graph..collect do |key, value| indent(depth) + "#{key}=\"#{value}\";" end end |
#write_nodes(nodes, depth) ⇒ Object
109 110 111 112 113 |
# File 'lib/coo-coo/dot.rb', line 109 def write_nodes(nodes, depth) nodes.collect do |node| indent(depth) + "#{node.name}[#{(node.)}];" end end |
#write_options(options) ⇒ Object
122 123 124 125 126 |
# File 'lib/coo-coo/dot.rb', line 122 def () .collect do |key, value| "#{key}=\"#{value}\"" end.join(",") end |