Class: Que::View::Pagination

Inherits:
Object
  • Object
show all
Defined in:
lib/que/view/pagination.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params: {}) ⇒ Pagination

Returns a new instance of Pagination.



8
9
10
11
12
# File 'lib/que/view/pagination.rb', line 8

def initialize(params: {})
  @page = params[:page]
  @count = params[:count]
  @per_page = params[:per_page]
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



6
7
8
# File 'lib/que/view/pagination.rb', line 6

def count
  @count
end

#pageObject (readonly)

Returns the value of attribute page.



6
7
8
# File 'lib/que/view/pagination.rb', line 6

def page
  @page
end

#per_pageObject (readonly)

Returns the value of attribute per_page.



6
7
8
# File 'lib/que/view/pagination.rb', line 6

def per_page
  @per_page
end

Instance Method Details

#first_page?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/que/view/pagination.rb', line 40

def first_page?
  page == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/que/view/pagination.rb', line 36

def last_page?
  page == total_pages
end

#next_pageObject



20
21
22
# File 'lib/que/view/pagination.rb', line 20

def next_page
  page + 1 unless last_page?
end

#next_page?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/que/view/pagination.rb', line 24

def next_page?
  page < total_pages
end

#offsetObject



14
15
16
17
18
# File 'lib/que/view/pagination.rb', line 14

def offset
  return 0 if page == 1

  per_page * (page.to_i - 1)
end

#previous_pageObject



28
29
30
# File 'lib/que/view/pagination.rb', line 28

def previous_page
  page - 1 unless first_page?
end

#previous_page?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/que/view/pagination.rb', line 32

def previous_page?
  page > 1
end

#total_pagesObject



44
45
46
# File 'lib/que/view/pagination.rb', line 44

def total_pages
  (count / per_page.to_f).ceil
end