class GraphNjae::Vertex
A vertex in a graph. The edge can have arbitrary attributes,treated as method names.
Public Class Methods
new(values = {})
click to toggle source
Calls superclass method
# File lib/graph.njae/vertex.rb, line 7 def initialize(values = {}) super(values) self.edges = [] self end
Public Instance Methods
<<(other)
click to toggle source
connect(other, edge_attributes = {})
click to toggle source
neighbours()
click to toggle source
Return the set of neighbouring vertices
# File lib/graph.njae/vertex.rb, line 31 def neighbours #vertices = self.edges.map {|e| e.vertices}.flatten #vertices_to_me = vertices.select {|v| v == self} #other_vertices = vertices.select {|v| v != self} #(vertices_to_me[1..-1] || []) + other_vertices# self.edges.map {|e| e.vertices.take_while {|v| v != self} + e.vertices.drop_while {|v| v != self}[1..-1]}.flatten end
to_dot(opts = {}) { |self| ... }
click to toggle source
# File lib/graph.njae/vertex.rb, line 44 def to_dot(opts = {}) if block_given? yield self else dot = self.object_id.to_s if opts.size > 0 dot << ' {' dot << opts.keys.map { |k| (k.to_s + ' = "' + self.instance_eval(opts[k].to_s).to_s) + '"' }.join(', ') dot << '}' end dot << ';' end end
to_s()
click to toggle source
# File lib/graph.njae/vertex.rb, line 40 def to_s '<V: ' + self.name.to_s + '>' end