class Thoth::Pager

The Pager class provides a simple wrapper around a paginated Sequel dataset.

Public Class Methods

new(dataset, url) click to toggle source

Initializes a new Pager instance wrapping the given Sequel dataset and using url as the template for all generated URLs. url should be a string containing an sprintf flag (such as %s) in place of the page number.

# File lib/thoth/helper/pagination.rb, line 38
def initialize(dataset, url)
  @dataset = dataset
  @url     = url
end

Public Instance Methods

current_page() click to toggle source

Returns the number of the current page.

# File lib/thoth/helper/pagination.rb, line 44
def current_page
  @dataset.current_page
end
current_page_record_count() click to toggle source

Returns the number of records in the current page.

# File lib/thoth/helper/pagination.rb, line 49
def current_page_record_count
  @dataset.current_page_record_count
end
current_page_record_range() click to toggle source

Returns the record range for the current page.

# File lib/thoth/helper/pagination.rb, line 54
def current_page_record_range
  @dataset.current_page_record_range
end
navigate() { |page, url| ... } click to toggle source

Iterates over all pages within 5 steps from the current page, yielding the page number and URL for each.

navigation?() click to toggle source

Returns true if the total number of pages is greater than 1.

next_page() click to toggle source

Returns the number of the next page or nil if the current page is the last.

# File lib/thoth/helper/pagination.rb, line 73
def next_page
  @dataset.next_page
end
next_url() click to toggle source

Returns the URL for the next page or nil if the current page is the last.

# File lib/thoth/helper/pagination.rb, line 79
def next_url
  next_page ? url(next_page) : nil
end
page_count() click to toggle source

Returns the total number of pages.

# File lib/thoth/helper/pagination.rb, line 84
def page_count
  @dataset.page_count
end
page_range() click to toggle source

Returns the page range.

# File lib/thoth/helper/pagination.rb, line 89
def page_range
  @dataset.page_range
end
page_size() click to toggle source

Returns the number of records per page.

# File lib/thoth/helper/pagination.rb, line 94
def page_size
  @dataset.page_size
end
prev_page() click to toggle source

Returns the number of the previous page or nil if the current page is the first.

# File lib/thoth/helper/pagination.rb, line 100
def prev_page
  @dataset.prev_page
end
prev_url() click to toggle source

Returns the URL for the previous page or nil if the current page is the first.

# File lib/thoth/helper/pagination.rb, line 106
def prev_url
  prev_page ? url(prev_page) : nil
end
record_count() click to toggle source

Returns the total number of records in the dataset.

# File lib/thoth/helper/pagination.rb, line 111
def record_count
  @dataset.pagination_record_count
end
url(page) click to toggle source

Returns the URL for the specified page number.

# File lib/thoth/helper/pagination.rb, line 116
def url(page)
  @url.to_s.gsub('__page__', page.to_i.to_s)
end