Class: DmPagination::Paginator::Solo

Inherits:
Base
  • Object
show all
Defined in:
lib/dm-pagination/paginator/solo.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 = 10, left = 5, right = 4) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/dm-pagination/paginator/solo.rb', line 4

def pages(window = 10, left = 5, right = 4)
  num_of_pages = num_pages
  return [] if num_of_pages <= 1
  right_page = page + right
  if right_page > num_of_pages
    right_page = num_of_pages
  elsif right_page < window
    right_page = window
  end
  left_page = if num_of_pages - right_page < right
    page - (window - (right_page - page + 1))
  else
    page - left
  end
  left_page = 1 if left_page <= 0
  (left_page..right_page)
end