Class: Nodes::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/appswarm/routing/routing.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(from) ⇒ Path

Returns a new instance of Path.



102
103
104
105
106
107
108
# File 'lib/appswarm/routing/routing.rb', line 102

def initialize(from)
  if from.is_a?(Array)
    @nodes=from
  else
    @nodes=[from]
  end
end

Instance Attribute Details

#nodesObject (readonly)

Returns the value of attribute nodes.



101
102
103
# File 'lib/appswarm/routing/routing.rb', line 101

def nodes
  @nodes
end

Instance Method Details

#<<(node) ⇒ Object



109
110
111
# File 'lib/appswarm/routing/routing.rb', line 109

def <<(node)
  @nodes << node
end

#initialize_copy(s) ⇒ Object



122
123
124
125
126
127
# File 'lib/appswarm/routing/routing.rb', line 122

def initialize_copy(s)
  #puts "S:",*s,s
  #exit
  @nodes=s.nodes.clone
  #Path.new(@nodes.clone)
end

#lastObject

Path.new(@nodes.clone)



128
129
130
# File 'lib/appswarm/routing/routing.rb', line 128

def last
  @nodes[-1]
end

#to_sObject



131
132
133
# File 'lib/appswarm/routing/routing.rb', line 131

def to_s
  "[#{@nodes.length} - #{value}]"
end

#valueObject



112
113
114
115
116
117
118
119
120
121
# File 'lib/appswarm/routing/routing.rb', line 112

def value
  a=(1..(@nodes.length-1)).to_a
  
  val=a.inject(0){|old,i|
    a=@nodes[i-1]
    b=@nodes[i]
    old.to_i+a.distance(b).to_i
  }
  val
end