class Nazrin::PaginatedArray

Attributes

current_page[R]
per_page[R]
total_count[R]

Public Class Methods

new(collection, page, per_page, total_count) click to toggle source
# File lib/nazrin/paginated_array.rb, line 5
def initialize(collection, page, per_page, total_count)
  @current_page = page
  @per_page = per_page
  @total_count = total_count
  replace collection
end

Public Instance Methods

first_page?() click to toggle source

first page of the collections?

# File lib/nazrin/paginated_array.rb, line 13
def first_page?
  current_page == 1
end
last_page?() click to toggle source

last page of the collections?

# File lib/nazrin/paginated_array.rb, line 18
def last_page?
  current_page >= total_pages
end
next_page() click to toggle source

next page number in the collections

# File lib/nazrin/paginated_array.rb, line 33
def next_page
  current_page + 1 unless last_page? || out_of_bounds?
end
out_of_bounds?() click to toggle source

out of bounds of the collections?

# File lib/nazrin/paginated_array.rb, line 38
def out_of_bounds?
  current_page > total_pages
end
previous_page() click to toggle source

previous page number in the collections

# File lib/nazrin/paginated_array.rb, line 28
def previous_page
  current_page - 1 unless first_page? || out_of_bounds?
end
total_pages() click to toggle source

total number of pages

# File lib/nazrin/paginated_array.rb, line 23
def total_pages
  (total_count.to_f / per_page).ceil
end