Class: Abuelo::Node

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

Overview

Class Node provides a representation of a node. A node has a name. Any object may be attached on initialization.

Author:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, object = nil) ⇒ Node

Initialiazises the node with its name.

Parameters:

  • name (String)

    of the node

  • object (Object) (defaults to: nil)

    to attach to the node. This is useful on some algorithm implementations.



25
26
27
28
# File 'lib/abuelo/node.rb', line 25

def initialize(name, object = nil)
  @name   = name
  @object = object
end

Instance Attribute Details

#graphAbuelo::Graph

Returns associated graph.

Returns:



16
17
18
# File 'lib/abuelo/node.rb', line 16

def graph
  @graph
end

#nameString (readonly)

Returns name.

Returns:

  • (String)

    name



10
11
12
# File 'lib/abuelo/node.rb', line 10

def name
  @name
end

#objectObject (readonly)

Returns attached object.

Returns:

  • (Object)

    attached object



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

def object
  @object
end

Instance Method Details

#==(other_node) ⇒ Boolean

Equality check.

Parameters:

Returns:

  • (Boolean)

    true if name is equal



51
52
53
# File 'lib/abuelo/node.rb', line 51

def ==(other_node)
  self.name == other_node.name
end

#edgesArray<Abuelo::Edge>

Returns list of edges starting from the node.

Returns:

  • (Array<Abuelo::Edge>)

    list of edges starting from the node



33
34
35
# File 'lib/abuelo/node.rb', line 33

def edges
  graph.edges_for_node(self) if graph
end

#to_sString

Returns human readable representation of node.

Returns:

  • (String)

    human readable representation of node



40
41
42
# File 'lib/abuelo/node.rb', line 40

def to_s
  @name
end