Class: MOSAIK::Graph::Cluster

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/mosaik/graph/cluster.rb

Overview

Cluster of vertices

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, attributes = T.let({}, Attributes)) ⇒ Cluster

Returns a new instance of Cluster.



23
24
25
26
27
# File 'lib/mosaik/graph/cluster.rb', line 23

def initialize(id, attributes = T.let({}, Attributes))
  @attributes = attributes
  @id = id
  @vertices = T.let(Set.new, T::Set[Vertex])
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



20
21
22
# File 'lib/mosaik/graph/cluster.rb', line 20

def attributes
  @attributes
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/mosaik/graph/cluster.rb', line 14

def id
  @id
end

#verticesObject (readonly)

Returns the value of attribute vertices.



17
18
19
# File 'lib/mosaik/graph/cluster.rb', line 17

def vertices
  @vertices
end

Instance Method Details

#add_vertex(vertex) ⇒ Object



30
31
32
# File 'lib/mosaik/graph/cluster.rb', line 30

def add_vertex(vertex)
  vertices << vertex
end

#inspectObject



40
41
42
# File 'lib/mosaik/graph/cluster.rb', line 40

def inspect
  "#<#{self.class.name} id=#{id} vertices=#{vertices.size} attributes=#{attributes.map { |k, v| "#{k}: #{v}" }.join(', ')}>"
end

#remove_vertex(vertex) ⇒ Object



35
36
37
# File 'lib/mosaik/graph/cluster.rb', line 35

def remove_vertex(vertex)
  vertices.delete(vertex)
end