Class: Graph::Edge

Inherits:
Thingy
  • Object
show all
Defined in:
lib/graph.rb

Overview

An edge in a graph.

Instance Attribute Summary collapse

Attributes inherited from Thingy

#attributes, #graph

Instance Method Summary collapse

Methods inherited from Thingy

#attributes?, #initialize_copy, #label

Constructor Details

#initialize(graph, from, to) ⇒ Edge

Create a new edge in graph from from to to.



469
470
471
472
473
# File 'lib/graph.rb', line 469

def initialize graph, from, to
  super graph
  self.from = from
  self.to = to
end

Instance Attribute Details

#fromObject

Returns the value of attribute from.



464
465
466
# File 'lib/graph.rb', line 464

def from
  @from
end

#toObject

Returns the value of attribute to.



464
465
466
# File 'lib/graph.rb', line 464

def to
  @to
end

Instance Method Details

#to_sObject

Returns the edge in dot syntax.



478
479
480
481
482
483
484
485
# File 'lib/graph.rb', line 478

def to_s
  fromto = "%p -> %p" % [from.name, to.name]
  if self.attributes? then
    "%-20s [ %-20s ]" % [fromto, attributes.join(',')]
  else
    fromto
  end
end