Class: Hanami::Pagination::MockPager

Inherits:
Object
  • Object
show all
Defined in:
lib/hanami/pagination/mock_pager.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(current_page, total_pages) ⇒ MockPager

Returns a new instance of MockPager.



6
7
8
9
# File 'lib/hanami/pagination/mock_pager.rb', line 6

def initialize(current_page, total_pages)
  @current_page = current_page
  @total_pages = total_pages
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



4
5
6
# File 'lib/hanami/pagination/mock_pager.rb', line 4

def current_page
  @current_page
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



4
5
6
# File 'lib/hanami/pagination/mock_pager.rb', line 4

def total_pages
  @total_pages
end

Instance Method Details

#first_page?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/hanami/pagination/mock_pager.rb', line 27

def first_page?
  current_page == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/hanami/pagination/mock_pager.rb', line 31

def last_page?
  current_page == total_pages
end

#next_pageObject



11
12
13
# File 'lib/hanami/pagination/mock_pager.rb', line 11

def next_page
  [current_page + 1, total_pages].min
end

#prev_pageObject



15
16
17
# File 'lib/hanami/pagination/mock_pager.rb', line 15

def prev_page
  [current_page - 1, 1].max
end

#totalObject



19
20
21
# File 'lib/hanami/pagination/mock_pager.rb', line 19

def total
  total_pages
end