Module: VORuby::ActiveVOTable::Pager

Defined in:
lib/voruby/active_votable/active_votable.rb

Overview

Paging methods for data.

Constant Summary collapse

DEFAULT_PER_PAGE =
25

Instance Method Summary collapse

Instance Method Details

#each_page(page_size = nil, options = {}) ⇒ Object



256
257
258
259
260
261
262
# File 'lib/voruby/active_votable/active_votable.rb', line 256

def each_page(page_size=nil, options={})
  num_per_page = page_size || per_page
  
  (1..(count().to_f / num_per_page.to_f).ceil()).each do |n|
    yield(page(n, num_per_page), n)
  end
end

#page(p = 1, page_size = nil, options = {}) ⇒ Object



247
248
249
250
251
252
253
254
# File 'lib/voruby/active_votable/active_votable.rb', line 247

def page(p=1, page_size=nil, options={})
  options ||= {}
  
  options[:limit] = page_size || per_page
  options[:offset] = options[:limit] * (p - 1)
  
  find(:all, options)
end

#per_pageObject



243
244
245
# File 'lib/voruby/active_votable/active_votable.rb', line 243

def per_page
  @per_page || DEFAULT_PER_PAGE
end

#per_page=(n) ⇒ Object



239
240
241
# File 'lib/voruby/active_votable/active_votable.rb', line 239

def per_page=(n)
  @per_page = n
end