Module: Tangle::GraphEdges

Included in:
Graph
Defined in:
lib/tangle/graph_edges.rb

Overview

Edge related methods in a graph

Instance Method Summary collapse

Instance Method Details

#add_edge(*vertices, **kvargs) ⇒ Object

Add a new edge to the graph

add_edge(vtx1, vtx2, …) => Edge



19
20
21
22
23
24
# File 'lib/tangle/graph_edges.rb', line 19

def add_edge(*vertices, **kvargs)
  edge = self.class::Edge.new(*vertices, mixins: @mixins, **kvargs)
  insert_edge(edge)
  vertices.each { |vertex| callback(vertex, :edge_added, edge) }
  edge
end

#edges(vertex = nil) ⇒ Object

Get all edges.

edges => Array



10
11
12
13
# File 'lib/tangle/graph_edges.rb', line 10

def edges(vertex = nil)
  return @edges if vertex.nil?
  @vertices.fetch(vertex)
end

#remove_edge(edge) ⇒ Object

Remove an edge from the graph



27
28
29
30
# File 'lib/tangle/graph_edges.rb', line 27

def remove_edge(edge)
  delete_edge(edge)
  edge.each_vertex { |vertex| callback(vertex, :edge_removed, edge) }
end