Class: RubyGraphWalker::Edge

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Edge

Returns a new instance of Edge.



32
33
34
35
36
37
38
39
40
41
# File 'lib/graph.rb', line 32

def initialize(args = {})
  [:name, :to, :proc].each { |key| raise "#{key} is not defined for Edge #{args}" unless args[key] }
  @name = args[:name]
  @from = args[:from]
  @to = args[:to]
  @weight = args[:weight] || 1
  @visited = args[:visited] || false
  @proc = args[:proc]
  @error_count = 0
end

Instance Attribute Details

#error_countObject

Returns the value of attribute error_count.



31
32
33
# File 'lib/graph.rb', line 31

def error_count
  @error_count
end

#fromObject

Returns the value of attribute from.



31
32
33
# File 'lib/graph.rb', line 31

def from
  @from
end

#nameObject

Returns the value of attribute name.



31
32
33
# File 'lib/graph.rb', line 31

def name
  @name
end

#procObject

Returns the value of attribute proc.



31
32
33
# File 'lib/graph.rb', line 31

def proc
  @proc
end

#toObject

Returns the value of attribute to.



31
32
33
# File 'lib/graph.rb', line 31

def to
  @to
end

#visitedObject

Returns the value of attribute visited.



31
32
33
# File 'lib/graph.rb', line 31

def visited
  @visited
end

#weightObject

Returns the value of attribute weight.



31
32
33
# File 'lib/graph.rb', line 31

def weight
  @weight
end

Instance Method Details

#runObject



43
44
45
46
# File 'lib/graph.rb', line 43

def run
  @proc.call
  @visited = true
end