Class: DmPagination::Paginator::Trio

Inherits:
Base
  • Object
show all
Defined in:
lib/dm-pagination/paginator/trio.rb

Instance Attribute Summary

Attributes inherited from Base

#num_pages, #page

Instance Method Summary collapse

Methods inherited from Base

#count, #initialize, #method_missing, #respond_to?, #to_json

Constructor Details

This class inherits a constructor from DmPagination::Paginator::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DmPagination::Paginator::Base

Instance Method Details

#pages(window = 5, left = 2, right = 2) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/dm-pagination/paginator/trio.rb', line 4

def pages(window = 5, left = 2, right = 2)
  return [] if num_pages <= 1
  (1..num_pages).inject([]) do |result, i|
    i <= left || (num_pages - i) < right || (i-page).abs < window ?
      result << i : (result.last.nil? ? result : result << nil)
  end
end