Class: GRATR::Arc

Inherits:
Struct::ArcBase
  • Object
show all
Defined in:
lib/gratr/edge.rb

Direct Known Subclasses

Edge, MultiArc

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(p_source, p_target, p_label = nil) ⇒ Arc

Returns a new instance of Arc.



41
42
43
# File 'lib/gratr/edge.rb', line 41

def initialize(p_source,p_target,p_label=nil)
  super(p_source, p_target, p_label)
end

Class Method Details

.[](p_source, p_target, p_label = nil) ⇒ Object

Shortcut constructor. Instead of Arc.new(1,2) one can use Arc



68
69
70
# File 'lib/gratr/edge.rb', line 68

def self.[](p_source, p_target, p_label=nil)
  new(p_source, p_target, p_label)
end

Instance Method Details

#<=>(rhs) ⇒ Object

Sort support



55
# File 'lib/gratr/edge.rb', line 55

def <=>(rhs) [source,target] <=> [rhs.source,rhs.target]; end

#eql?(other) ⇒ Boolean Also known as: ==

Ignore labels for equality

Returns:

  • (Boolean)


46
# File 'lib/gratr/edge.rb', line 46

def eql?(other) self.class == other.class and target==other.target and source==other.source; end

#hashObject

Hash is defined in such a way that label is not part of the hash value



65
# File 'lib/gratr/edge.rb', line 65

def hash() source.hash ^ (target.hash+1); end

#inspectObject



72
# File 'lib/gratr/edge.rb', line 72

def inspect() "#{self.class.to_s}[#{source.inspect},#{target.inspect},#{label.inspect}]"; end

#reverseObject

Returns (v,u) if self == (u,v).



52
# File 'lib/gratr/edge.rb', line 52

def reverse() self.class.new(target, source, label); end

#to_sObject

Arc.new.to_s => “(1-2 ‘label’)”



58
59
60
61
# File 'lib/gratr/edge.rb', line 58

def to_s
  l = label ? " '#{label.to_s}'" : ''
  "(#{source}-#{target}#{l})"
end