Placeholder
[graph.njae.git] / lib / graph.njae / edge.rb
index 6581033d2a885bbe4fe8beddf1eddfb38879b50a..4a1ba790d4f33570f53525cbd3f3c23660135240 100644 (file)
@@ -10,8 +10,8 @@ module GraphNjae
   # Each connection is handled by a Graph::Connection object, so that each end
   # of the Edge can have it's own attributes.
   class Edge < OpenStruct
-    def initialize
-      super
+    def initialize(values = {})
+      super(values)
       self.connections = []
       self
     end
@@ -20,6 +20,7 @@ module GraphNjae
     def <<(other)
       c = Connection.new
       c.end = other
+      other.edges << self unless other.edges.include? self
       self.connections << c
       self
     end
@@ -31,15 +32,15 @@ module GraphNjae
     
     # Return the connection object that joins this Edge to the specified Vertex
     def connection_at(vertex)
-      self.connections.select {|c| c.end.equal?  vertex}.first
+      self.connections.find {|c| c.end.equal?  vertex}
     end
   end
   
   # A connection between an Edge and a Vertex.The connection can have arbitrary attributes,
   # treated as method names.
   class Connection < OpenStruct
-    def initialize
-      super
+    def initialize(values = {})
+      super(values)
       self
     end
   end