Class: SameSame::Cluster

Inherits:
Object
  • Object
show all
Defined in:
lib/same_same/cluster.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dp, name = nil) ⇒ Cluster

Returns a new instance of Cluster.



7
8
9
10
# File 'lib/same_same/cluster.rb', line 7

def initialize( dp, name = nil )
  self.datapoints = dp
  self.name = name
end

Instance Attribute Details

#datapointsObject

note to self - unless I need to implement a heap more, i’m just wrapping an array and delegating…



5
6
7
# File 'lib/same_same/cluster.rb', line 5

def datapoints
  @datapoints
end

#nameObject

note to self - unless I need to implement a heap more, i’m just wrapping an array and delegating…



5
6
7
# File 'lib/same_same/cluster.rb', line 5

def name
  @name
end

Instance Method Details

#+(other) ⇒ Object



12
13
14
15
16
# File 'lib/same_same/cluster.rb', line 12

def +( other )
  names = [name, other.name].compact
  new_name = names.empty? ? nil : names.join("+")
  Cluster.new( datapoints + other.datapoints, new_name )
end

#inject(i, &block) ⇒ Object



22
23
24
# File 'lib/same_same/cluster.rb', line 22

def inject(i, &block)
  datapoints.inject(i, &block)
end

#sizeObject



18
19
20
# File 'lib/same_same/cluster.rb', line 18

def size
  datapoints.size
end