Module: Dagnabit::Edge::Connectivity

Defined in:
lib/dagnabit/edge/connectivity.rb

Overview

Methods for querying connectivity of edges.

Instance Method Summary collapse

Instance Method Details

#connecting(*vertices) ⇒ Array<ActiveRecord::Base>

Finds all edges connecting the given vertices.

More specifically, finds all edges such that the edge’s parent and child is one of the given vertices.

This means that should vertices belong to disjoint subgraphs be selected, e.g.

(a)  (d)
 |    |
(b)   e
 |    |
(c)   f

where () denotes a selected vertex, then only the edges for which both the parent and child vertices are present will be in the result set. In the above example, this means that while the a->b and b->c edges will be present, the d->e edge will not. To include the d->e edge, e would have to be in the vertex list.

Parameters:

  • vertices (Array<ActiveRecord::Base>)

    the vertices to consider

Returns:

  • (Array<ActiveRecord::Base>)

    a list of edges



30
31
32
33
34
# File 'lib/dagnabit/edge/connectivity.rb', line 30

def connecting(*vertices)
  ids = vertices.map(&:id)

  scoped(:conditions => { :parent_id => ids, :child_id => ids })
end