Class: Yargi::Digraph::Edge

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#graphObject (readonly) Also known as: digraph

Owning graph



15
16
17
# File 'lib/yargi/digraph_edge.rb', line 15

def graph
  @graph
end

#indexObject

Index in the vertices list of the owner



19
20
21
# File 'lib/yargi/digraph_edge.rb', line 19

def index
  @index
end

#sourceObject

Source vertex



22
23
24
# File 'lib/yargi/digraph_edge.rb', line 22

def source
  @source
end

#targetObject

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

#extremitiesObject

Returns edge extremities



46
47
48
# File 'lib/yargi/digraph_edge.rb', line 46

def extremities
  VertexSet[source, target]
end

#inspectObject

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_sObject

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