Class: RubyGraphWalker::Vertex

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Vertex

Returns a new instance of Vertex.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/graph.rb', line 7

def initialize(args = {})
  [:name, :edges, :trait].each { |key| raise "#{key} is not defined for Vertex #{args}" unless args[key] }
  @name = args[:name]
  @weight = args[:weight] || 1
  @trait = args[:trait]
  @visited = args[:visited] || false
  @weight = args[:zindex] || 0
  @edges = []

  args[:edges].each do |edge|
    e = Edge.new(edge)
    e.from = @name
    e.to = edge[:to]
    add_edge(e)
  end
end

Instance Attribute Details

#edgesObject

Returns the value of attribute edges.



6
7
8
# File 'lib/graph.rb', line 6

def edges
  @edges
end

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/graph.rb', line 6

def name
  @name
end

#traitObject

Returns the value of attribute trait.



6
7
8
# File 'lib/graph.rb', line 6

def trait
  @trait
end

#visitedObject

Returns the value of attribute visited.



6
7
8
# File 'lib/graph.rb', line 6

def visited
  @visited
end

#weightObject

Returns the value of attribute weight.



6
7
8
# File 'lib/graph.rb', line 6

def weight
  @weight
end

#zindexObject

Returns the value of attribute zindex.



6
7
8
# File 'lib/graph.rb', line 6

def zindex
  @zindex
end