X-Git-Url: https://git.njae.me.uk/?a=blobdiff_plain;f=lib%2Fgraph.njae%2Fedge.rb;fp=lib%2Fgraph.njae%2Fedge.rb;h=7fd99b771bec5082e96f6fe2ebef7e11e283814c;hb=99e4223d9b3baef392d4a6b0b996078f06fcadf7;hp=f3efc91eec9157301ece98c735663d2c94f0d1c8;hpb=2978dd081219adda6952feb65b1782cfe749f133;p=graph.njae.git

diff --git a/lib/graph.njae/edge.rb b/lib/graph.njae/edge.rb
index f3efc91..7fd99b7 100644
--- a/lib/graph.njae/edge.rb
+++ b/lib/graph.njae/edge.rb
@@ -1,5 +1,3 @@
-require 'ostruct'
-
 # A simple graph library
 
 module GraphNjae
@@ -48,6 +46,23 @@ module GraphNjae
     def to_s
       '<E: ' + self.type.to_s + ' [' + self.vertices.map {|n| n.to_s}.join(', ') + '] >'
     end
+    
+    def to_dot(opts = {})
+      if block_given?
+        yield self
+      else
+        dot = self.connections[0].end.object_id.to_s + " -- " + self.connections[1].end.object_id.to_s
+        if opts.size > 0
+          dot << ' {'
+          dot << opts.keys.map { |k|
+            (k.to_s + ' = "' + self.instance_eval(opts[k].to_s).to_s) + '"'
+                        }.join(', ')
+          dot << '}'
+        end
+        dot << ';'
+      end
+    end
+
   end
   
   # A connection between an Edge and a Vertex.The connection can have arbitrary attributes,