Module: GRATR::ArcNumber

Included in:
MultiArc, MultiEdge
Defined in:
lib/gratr/edge.rb

Overview

This module provides for internal numbering of edges for differentiating between mutliple edges

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#numberObject

Used to differentiate between mutli-edges



111
112
113
# File 'lib/gratr/edge.rb', line 111

def number
  @number
end

Class Method Details

.included(cl) ⇒ Object

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



128
129
130
131
132
133
# File 'lib/gratr/edge.rb', line 128

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

Instance Method Details

#<=>(rhs) ⇒ Object



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

def <=>(rhs) (result = super(rhs)) == 0 ? number <=> rhs.number : result; end

#==(rhs) ⇒ Object



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

def ==(rhs) eql?(rhs); end

#eql?(rhs) ⇒ Boolean

Returns:

  • (Boolean)


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

def eql?(rhs) super(rhs) and (rhs.number.nil? or number.nil? or number == rhs.number); end

#hashObject



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

def hash() super ^ number.hash; end

#initialize(p_source, p_target, p_number, p_label = nil) ⇒ Object



113
114
115
116
# File 'lib/gratr/edge.rb', line 113

def initialize(p_source,p_target,p_number,p_label=nil)
  self.number = p_number 
  super(p_source, p_target, p_label)
end

#inspectObject



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

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

#reverseObject

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



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

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

#to_sObject



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

def to_s() super + "[#{number}]"; end