Sha256: 69707c6e4112ed005583f13a62f7ff24441b658208472b9a58c15e93d4fc6318
Contents?: true
Size: 1.13 KB
Versions: 20
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true module Karafka module Web module Ui module Lib # A simple wrapper for paginating array related data structures class PaginateArray # @param array [Array] array we want to paginate # @param current_page [Integer] page we want to be on # @return [Array<Array, <Integer, nil>>] Array with two elements: first is the array with # data of the given page and second is the next page number of nil in case there is # no next page (end of data) def call(array, current_page) slices = array.each_slice(per_page).to_a current_data = slices[current_page - 1] || [] if slices.count >= current_page - 1 && current_data.size >= per_page next_page = current_page + 1 else next_page = nil end [current_data, next_page] end private # @return [Integer] how many elements should we display in the UI def per_page ::Karafka::Web.config.ui.per_page end end end end end end
Version data entries
20 entries across 20 versions & 1 rubygems