Class: Node

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Node

Returns a new instance of Node.



4
5
6
7
# File 'lib/rgraph/node.rb', line 4

def initialize(attributes)
  @attributes = attributes
  @neighbours = []
end

Instance Attribute Details

#neighboursObject

Returns the value of attribute neighbours.



2
3
4
# File 'lib/rgraph/node.rb', line 2

def neighbours
  @neighbours
end

Instance Method Details

#[](attribute) ⇒ Object



17
18
19
# File 'lib/rgraph/node.rb', line 17

def [](attribute)
  @attributes[attribute]
end

#degreeObject



9
10
11
# File 'lib/rgraph/node.rb', line 9

def degree
  @neighbours.size
end

#has_neighbour?(node) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/rgraph/node.rb', line 13

def has_neighbour?(node)
  @neighbours.include?(node)
end