class GraphElements::VertexDefault

Represent graph's vertex

Attributes

color[RW]
visits[RW]

Public Class Methods

new(id, type, attributes = {}) click to toggle source

Constructor to vertex

Params:
id

Integer user id

type

Class of vertex

attributes

Hash aditional attributes of vertex

# File lib/social_framework/graphs/graph_elements.rb, line 52
def initialize id, type, attributes = {}
  @id = id
  @type = type
  @edges = Array.new
  @visits = 0
  @color = :white
  @attributes = attributes
end

Public Instance Methods

==(other) click to toggle source

Overriding equal method to compare vertex by id Returns true if id is equal or false if not

# File lib/social_framework/graphs/graph_elements.rb, line 63
def ==(other)
  self.id == other.id and self.type == other.type
end
add_edge(destiny, label = "") click to toggle source

Add edges to vertex

Params:
destiny

Vertex destiny to edge

label

String label to edge

Returns edge created

# File lib/social_framework/graphs/graph_elements.rb, line 78
def add_edge destiny, label = ""
  edge = @edges.select { |e| e.destiny == destiny }.first

  if edge.nil?
    edge = EdgeDefault.new self, destiny
    @edges << edge
  end

  edge.labels << label
end
hash() click to toggle source

Overriding hash method to always equals Returns id hash

# File lib/social_framework/graphs/graph_elements.rb, line 69
def hash
  self.id.hash
end