Class: Plexus::Arc

Inherits:
Struct::ArcBase
  • Object
show all
Defined in:
lib/plexus/arc.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



10
11
12
# File 'lib/plexus/arc.rb', line 10

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.



49
50
51
# File 'lib/plexus/arc.rb', line 49

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

Instance Method Details

#<=>(rhs) ⇒ Object

Sort support.



27
28
29
# File 'lib/plexus/arc.rb', line 27

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

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

Ignore labels for equality.



15
16
17
18
# File 'lib/plexus/arc.rb', line 15

def eql?(other)
  same_class = self.class.ancestors.include?(other.class) || other.class.ancestors.include?(self.class)
  same_class && target == other.target && source == other.source
end

#hashObject

Hash is defined in such a way that label is not part of the hash value FIXME: I had to get rid of that in order to make to_dot_graph work, but I can't figure it out (doesn't show up in the stack!)



42
43
44
# File 'lib/plexus/arc.rb', line 42

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

#inspectObject



53
54
55
# File 'lib/plexus/arc.rb', line 53

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

#reverseObject

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



22
23
24
# File 'lib/plexus/arc.rb', line 22

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

#to_sObject

Arc.to_s => “(1-2)” Arc.to_s => “(1-2 test)”



33
34
35
36
# File 'lib/plexus/arc.rb', line 33

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