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

- (Arc) initialize(p_source, p_target, p_label = nil)



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

+ (Object) [](p_source, p_target, p_label = nil)

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

- (Object) <=>(rhs)

Sort support.



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

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

- (Boolean) eql?(other) 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

- (Object) hash

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

- (Object) inspect



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

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

- (Object) reverse

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

- (Object) to_s

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