class RestFtpDaemon::Paginate

Attributes

all[RW]
filter[W]

Class options

Public Class Methods

new(data) click to toggle source
# File lib/rest-ftp-daemon/paginate.rb, line 9
def initialize data
  # Defaults
  @pages = 0
  @total = 0
  @data = []
  @filter = ''
  @page = 1
  @pages = 1
  @all = false

  # Ensure data set is countable
  return unless data.is_a? Enumerable
  @data = data

  # Count elements
  @total = @data.count

  # Count pages
  @pages = (@total.to_f / DEFAULT_PAGE_SIZE).ceil
  @pages = 1 if @pages < 1
end

Public Instance Methods

browser() click to toggle source
# File lib/rest-ftp-daemon/paginate.rb, line 35
def browser
  return if @all

  out = []
  1.upto(@pages) do |p|
    out << link(p)
  end
  out.join()
end
page=(raw_page) click to toggle source
# File lib/rest-ftp-daemon/paginate.rb, line 31
def page= raw_page
  @page = [1, raw_page.to_i, @pages].sort[1]
end
subset() click to toggle source
# File lib/rest-ftp-daemon/paginate.rb, line 45
def subset
  return @data if @all

  size = DEFAULT_PAGE_SIZE.to_i
  offset = (@page-1) * size
  @data[offset, size]
end

Private Instance Methods