Class: Blackcal::SlotMatrix

Inherits:
Object
  • Object
show all
Defined in:
lib/blackcal/slot_matrix.rb

Overview

Slot matrix

Instance Method Summary collapse

Constructor Details

#initialize(slots) ⇒ SlotMatrix

Initialize slot matrix

Parameters:

  • slots (Integer)

    max elements in each slot



8
9
10
11
# File 'lib/blackcal/slot_matrix.rb', line 8

def initialize(slots)
  @matrix = [[]]
  @slots = slots
end

Instance Method Details

#<<(value) ⇒ Object

Add value

Parameters:

  • value (Object, nil)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/blackcal/slot_matrix.rb', line 20

def <<(value)
  array = @matrix[@matrix.length - 1] || []

  # move to next slot when max slot length is reached
  if array.length >= @slots
    array = []
    @matrix << array
  end

  array << value
end

#dataArray<Array<Object>>

Returns data.

Returns:

  • (Array<Array<Object>>)

    data



14
15
16
# File 'lib/blackcal/slot_matrix.rb', line 14

def data
  @matrix
end