class Gumdrop::Util::Pager

Attributes

all[R]
base_path[R]
current_page[R]
page_sets[R]
pages[R]

Public Class Methods

new(articles, base_path="/page", page_size=5) click to toggle source
# File lib/gumdrop/util/pager.rb, line 6
def initialize(articles, base_path="/page", page_size=5)
  @all= articles
  @page_size= page_size
  @base_path= base_path
  @page_sets= @all.in_groups_of(page_size, false)
  @pages= []
  @current_page=1
  @page_sets.each do |art_ary|
    @pages << HashObject.from({
      items: art_ary,
      page: @current_page,
      uri: "#{base_path}/#{current_page}",
      pager: self
    })
    @current_page += 1
  end
  @current_page= nil
end

Public Instance Methods

[](key) click to toggle source
# File lib/gumdrop/util/pager.rb, line 59
def [](key)
  @pages[key]
end
current() click to toggle source
# File lib/gumdrop/util/pager.rb, line 25
def current
  @pages.fetch(@current_page, nil)
end
each() { |page_set| ... } click to toggle source
# File lib/gumdrop/util/pager.rb, line 41
def each
  @current_page=1
  @pages.each do |page_set|
    yield page_set
    @current_page += 1
  end
  @current_page= nil
end
each_with_index() { |page_set, current_page - 1| ... } click to toggle source
# File lib/gumdrop/util/pager.rb, line 50
def each_with_index
  @current_page=1
  @pages.each do |page_set|
    yield page_set, @current_page - 1
    @current_page += 1
  end
  @current_page= nil
end
first() click to toggle source
# File lib/gumdrop/util/pager.rb, line 33
def first
  @pages.first
end
last() click to toggle source
# File lib/gumdrop/util/pager.rb, line 37
def last
  @pages.last
end
length() click to toggle source
# File lib/gumdrop/util/pager.rb, line 29
def length
  @pages.length
end