class Blackcal::SlotMatrix

Slot matrix

Public Class Methods

new(slots) click to toggle source

Initialize slot matrix @param [Integer] slots max elements in each slot

# File lib/blackcal/slot_matrix.rb, line 8
def initialize(slots)
  @matrix = [[]]
  @slots = slots
end

Public Instance Methods

<<(value) click to toggle source

Add value @param [Object, nil] value

# 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
data() click to toggle source

@return [Array<Array<Object>>] data

# File lib/blackcal/slot_matrix.rb, line 14
def data
  @matrix
end