Sha256: 91a2196de82c38dae3d9bc1ad8b43494dc799a2d1ffc0823747ccf487fe00a30

Contents?: true

Size: 621 Bytes

Versions: 2

Compression:

Stored size: 621 Bytes

Contents

# frozen_string_literal: true

module Blackcal
  # Slot matrix
  class SlotMatrix
    # Initialize slot matrix
    # @param [Integer] slots max elements in each slot
    def initialize(slots)
      @matrix = [[]]
      @slots = slots
    end

    # @return [Array<Array<Object>>] data
    def data
      @matrix
    end

    # Add value
    # @param [Object, nil] value
    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
blackcal-0.5.0 lib/blackcal/slot_matrix.rb
blackcal-0.3.0 lib/blackcal/slot_matrix.rb