Class: Karafka::Web::Ui::Lib::Paginations::Paginators::Arrays
- Defined in:
- lib/karafka/web/ui/lib/paginations/paginators/arrays.rb
Overview
A simple wrapper for paginating array related data structures We call this with plural (same with Sets
) to avoid confusion with Ruby classes
Class Method Summary collapse
-
.call(array, current_page) ⇒ Array<Array, Boolean>
Array with two elements: first is the array with data of the given page and second is a boolean flag with info if the elements we got are from the last page.
Methods inherited from Base
Class Method Details
.call(array, current_page) ⇒ Array<Array, Boolean>
Returns Array with two elements: first is the array with data of the given page and second is a boolean flag with info if the elements we got are from the last page.
19 20 21 22 23 24 25 |
# File 'lib/karafka/web/ui/lib/paginations/paginators/arrays.rb', line 19 def call(array, current_page) slices = array.each_slice(per_page).to_a current_data = slices[current_page - 1] || [] last_page = !(slices.count >= current_page - 1 && current_data.size >= per_page) [current_data, last_page] end |