Class: Yargi::Digraph::Edge
- Inherits:
-
Object
- Object
- Yargi::Digraph::Edge
- Includes:
- Markable
- Defined in:
- lib/yargi/digraph_edge.rb
Overview
Edge inside a digraph
Methods reconnect, index= are provided for Digraph itself and are not intended to be used directly. Probably unexpectedly, source and target writers are provided as reconnection shortcuts and can be used by users.
Instance Attribute Summary collapse
-
#graph ⇒ Object
(also: #digraph)
readonly
Owning graph.
-
#index ⇒ Object
Index in the vertices list of the owner.
-
#source ⇒ Object
Source vertex.
-
#target ⇒ Object
Target vertex.
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares indexes.
-
#extremities ⇒ Object
Returns edge extremities.
-
#initialize(graph, index, source, target) ⇒ Edge
constructor
Creates an edge instance.
-
#inspect ⇒ Object
Inspects the vertex.
-
#reconnect(source, target) ⇒ Object
Reconnects source and target.
-
#to_s ⇒ Object
Returns a string representation.
Methods included from Markable
#add_marks, #get_mark, #has_mark?, #set_mark, #tag, #to_h
Constructor Details
#initialize(graph, index, source, target) ⇒ Edge
Creates an edge instance
28 29 30 31 |
# File 'lib/yargi/digraph_edge.rb', line 28 def initialize(graph, index, source, target) @graph, @index = graph, index @source, @target = source, target end |
Instance Attribute Details
#graph ⇒ Object (readonly) Also known as: digraph
Owning graph
15 16 17 |
# File 'lib/yargi/digraph_edge.rb', line 15 def graph @graph end |
#index ⇒ Object
Index in the vertices list of the owner
19 20 21 |
# File 'lib/yargi/digraph_edge.rb', line 19 def index @index end |
#source ⇒ Object
Source vertex
22 23 24 |
# File 'lib/yargi/digraph_edge.rb', line 22 def source @source end |
#target ⇒ Object
Target vertex
25 26 27 |
# File 'lib/yargi/digraph_edge.rb', line 25 def target @target end |
Instance Method Details
#<=>(other) ⇒ Object
Compares indexes
64 65 66 67 |
# File 'lib/yargi/digraph_edge.rb', line 64 def <=>(other) return nil unless Edge===other and self.graph==other.graph self.index <=> other.index end |
#extremities ⇒ Object
Returns edge extremities
46 47 48 |
# File 'lib/yargi/digraph_edge.rb', line 46 def extremities VertexSet[source, target] end |
#inspect ⇒ Object
Inspects the vertex
76 |
# File 'lib/yargi/digraph_edge.rb', line 76 def inspect; "e#{index}:#{source.inspect}->#{target.inspect}" end |
#reconnect(source, target) ⇒ Object
Reconnects source and target
37 38 39 40 |
# File 'lib/yargi/digraph_edge.rb', line 37 def reconnect(source, target) @source = source if source @target = target if target end |
#to_s ⇒ Object
Returns a string representation
73 |
# File 'lib/yargi/digraph_edge.rb', line 73 def to_s; "e#{index}:#{source.to_s}->#{target.to_s}" end |