Class: Clustr::Node

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

Overview

Represents a single node within a cluster. Note that the physical entity represented by this node may occur several times in other Cluster.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, properties = {}) ⇒ Node

Creates a new Clustr::Node, taking a unique identifier for the node within the Cluster and a set of optional, properties to further describe or provide additional information about the node.

Parameters:

  • id (mixed)

    of the node within the cluster.

  • properties (hash) (defaults to: {})

    to set for this node.



16
17
18
19
20
# File 'lib/clustr/node.rb', line 16

def initialize(id, properties = {})
  @id = id
  @created = Time.now.to_i
  @properties = properties
end

Instance Attribute Details

#createdObject (readonly)

Returns the value of attribute created.



7
8
9
# File 'lib/clustr/node.rb', line 7

def created
  @created
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/clustr/node.rb', line 7

def id
  @id
end

#propertiesObject (readonly)

Returns the value of attribute properties.



7
8
9
# File 'lib/clustr/node.rb', line 7

def properties
  @properties
end

Instance Method Details

#[](key) ⇒ mixed

Retrieves a specific key from the property set that accompanies this node.

Parameters:

  • key (string)

    of the property value to retrieve.

Returns:

  • (mixed)

    the corresponding value for the property key.



28
29
30
# File 'lib/clustr/node.rb', line 28

def [](key)
  properties[key.to_s]
end