Class: GraphElements::Vertex
- Inherits:
-
Object
- Object
- GraphElements::Vertex
- Defined in:
- lib/social_framework/graphs/graph_elements.rb
Overview
Represent graph’s vertex
Instance Attribute Summary collapse
-
#attributes ⇒ Object
Returns the value of attribute attributes.
-
#color ⇒ Object
Returns the value of attribute color.
-
#edges ⇒ Object
Returns the value of attribute edges.
-
#id ⇒ Object
Returns the value of attribute id.
-
#type ⇒ Object
Returns the value of attribute type.
-
#visits ⇒ Object
Returns the value of attribute visits.
Instance Method Summary collapse
-
#==(other) ⇒ Object
(also: #eql?)
Overriding equal method to compare vertex by id Returns true if id is equal or false if not.
-
#add_edge(destiny, label = "") ⇒ Object
- Add edges to vertex ====== Params:
destiny Vertexdestiny to edgelabel-
Stringlabel to edge Returns edge created.
- Add edges to vertex ====== Params:
-
#hash ⇒ Object
Overriding hash method to always equals Returns id hash.
-
#initialize(id, type, attributes = {}) ⇒ Vertex
constructor
- Constructor to vertex ====== Params:
id -
Integeruser id Returns Vertex’s Instance.
- Constructor to vertex ====== Params:
Constructor Details
#initialize(id, type, attributes = {}) ⇒ Vertex
Constructor to vertex
Params:
id-
Integeruser id
Returns Vertex’s Instance
11 12 13 14 15 16 17 18 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 11 def initialize id, type, attributes = {} @id = id @type = type @edges = Array.new @visits = 0 @color = :white @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
5 6 7 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 5 def attributes @attributes end |
#color ⇒ Object
Returns the value of attribute color.
5 6 7 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 5 def color @color end |
#edges ⇒ Object
Returns the value of attribute edges.
5 6 7 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 5 def edges @edges end |
#id ⇒ Object
Returns the value of attribute id.
5 6 7 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 5 def id @id end |
#type ⇒ Object
Returns the value of attribute type.
5 6 7 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 5 def type @type end |
#visits ⇒ Object
Returns the value of attribute visits.
5 6 7 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 5 def visits @visits end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
Overriding equal method to compare vertex by id Returns true if id is equal or false if not
22 23 24 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 22 def ==(other) self.id == other.id and self.type == other.type end |
#add_edge(destiny, label = "") ⇒ Object
Add edges to vertex
Params:
destiny-
Vertexdestiny to edge label-
Stringlabel to edge
Returns edge created
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 39 def add_edge destiny, label = "" edge = @edges.select { |e| e.destiny == destiny }.first if edge.nil? edge = Edge.new self, destiny @edges << edge end edge.labels << label end |
#hash ⇒ Object
Overriding hash method to always equals Returns id hash
30 31 32 |
# File 'lib/social_framework/graphs/graph_elements.rb', line 30 def hash self.id.hash end |