Class: TinyPaginate::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/tiny_paginate/page.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_number:, collection:) ⇒ Page

Returns a new instance of Page.



5
6
7
8
# File 'lib/tiny_paginate/page.rb', line 5

def initialize(page_number:, collection:)
  @page_number = page_number
  @collection = collection
end

Instance Attribute Details

#collectionObject

Returns the value of attribute collection.



3
4
5
# File 'lib/tiny_paginate/page.rb', line 3

def collection
  @collection
end

#page_numberObject

Returns the value of attribute page_number.



3
4
5
# File 'lib/tiny_paginate/page.rb', line 3

def page_number
  @page_number
end

Instance Method Details

#first_page?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/tiny_paginate/page.rb', line 22

def first_page?
  page_number == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/tiny_paginate/page.rb', line 26

def last_page?
  page_number >= (collection.length.to_f / TinyPaginate.max_records_per_page).ceil
end

#next_pageObject



14
15
16
# File 'lib/tiny_paginate/page.rb', line 14

def next_page
  page_number + 1
end

#previous_pageObject



18
19
20
# File 'lib/tiny_paginate/page.rb', line 18

def previous_page
  page_number - 1
end

#recordsObject



10
11
12
# File 'lib/tiny_paginate/page.rb', line 10

def records
  collection.offset(offset).limit(TinyPaginate.max_records_per_page)
end