X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=lib%2Fgraph.njae%2Fgraph.rb;fp=lib%2Fgraph.njae%2Fgraph.rb;h=f3d00328d4a4956087ea0a276604417a74c19b7d;hb=282a96d68535bd39b4dcd08ff805ccfcfd8b9f10;hp=37b772030053c146f61e14c2c286a3ed60c4bd8a;hpb=99e4223d9b3baef392d4a6b0b996078f06fcadf7;p=graph.njae.git

diff --git a/lib/graph.njae/graph.rb b/lib/graph.njae/graph.rb
index 37b7720..f3d0032 100644
--- a/lib/graph.njae/graph.rb
+++ b/lib/graph.njae/graph.rb
@@ -36,6 +36,31 @@ module GraphNjae
       edge << vertex1 << vertex2
     end
     
+    def to_dot(opts = {})
+      vertex_args = opts[:vertex_args] || {}
+      vertex_block = opts[:vertex_block] || nil
+      edge_args = opts[:edge_args] || {}
+      edge_block = opts[:edge_block] || nil
+      dot = "graph {\n"
+      self.vertices.each do |v|
+        if vertex_block.nil?
+          dot << v.to_dot(vertex_args)
+        else
+          dot << v.do_dot(&vertex_block)
+        end
+        dot << "\n"
+      end
+      self.edges.each do |e|
+        if edge_block.nil?
+          dot << e.to_dot(edge_args)
+        else
+          dot << e.do_dot(&lambda {edge_block})
+        end
+        dot << "\n"
+      end
+      dot << '}'
+    end
+    
     # Form a product graph of this graph and the other.
     # Return the product graph.
     def product(other)