3 # A simple graph library
7 # An edge (or multiedge) in a graph. The edge can have arbitrary attributes,
8 # treated as method names.
10 # Each connection is handled by a Graph::Connection object, so that each end
11 # of the Edge can have it's own attributes.
12 class Edge
< OpenStruct
13 def initialize(values
= {})
19 # Connect this edge to a vertex
23 other
.edges
<< self unless other
.edges
.include? self
28 # Return the set of vertices this edge connects.
30 self.connections
.map
{|c
| c
.end}
33 # Return the connection object that joins this Edge to the specified Vertex
34 def connection_at(vertex
)
35 self.connections
.find
{|c
| c
.end.equal
? vertex
}
39 # A connection between an Edge and a Vertex.The connection can have arbitrary attributes,
40 # treated as method names.
41 class Connection
< OpenStruct
42 def initialize(values
= {})