Class: GRATR::Arc
- Inherits:
-
Struct::ArcBase
- Object
- Struct::ArcBase
- GRATR::Arc
- Defined in:
- lib/gratr/edge.rb
Class Method Summary collapse
-
.[](p_source, p_target, p_label = nil) ⇒ Object
Shortcut constructor.
Instance Method Summary collapse
-
#<=>(rhs) ⇒ Object
Sort support.
-
#eql?(other) ⇒ Boolean
(also: #==)
Ignore labels for equality.
-
#hash ⇒ Object
Hash is defined in such a way that label is not part of the hash value.
-
#initialize(p_source, p_target, p_label = nil) ⇒ Arc
constructor
A new instance of Arc.
- #inspect ⇒ Object
-
#reverse ⇒ Object
Returns (v,u) if self == (u,v).
-
#to_s ⇒ Object
Arc.new.to_s => “(1-2 ‘label’)”.
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
46 |
# File 'lib/gratr/edge.rb', line 46 def eql?(other) self.class == other.class and target==other.target and source==other.source; end |
#hash ⇒ Object
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 |
#inspect ⇒ Object
72 |
# File 'lib/gratr/edge.rb', line 72 def inspect() "#{self.class.to_s}[#{source.inspect},#{target.inspect},#{label.inspect}]"; end |
#reverse ⇒ Object
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_s ⇒ Object
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 |