Class: Paginator

Inherits:
Object
  • Object
show all
Defined in:
lib/zarchitect/paginator.rb

Constant Summary collapse

MAX =
15

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(base_url, page_number, ppp) ⇒ Paginator

Returns a new instance of Paginator.



6
7
8
9
10
11
12
13
14
# File 'lib/zarchitect/paginator.rb', line 6

def initialize(base_url, page_number, ppp)
  @base_url    = base_url    # used to construct urls to pages
  @page_number = page_number # number of pages in total
  @curr_page   = 1           # current page
  @range       = Array.new   # numbers of pages in pagination
  @max         = MAX         # how many pages to be shown in pagination
  @posts_per_page = ppp
  update_range
end

Instance Attribute Details

#curr_pageObject (readonly)

Returns the value of attribute curr_page.



2
3
4
# File 'lib/zarchitect/paginator.rb', line 2

def curr_page
  @curr_page
end

#maxObject (readonly)

Returns the value of attribute max.



2
3
4
# File 'lib/zarchitect/paginator.rb', line 2

def max
  @max
end

#page_numberObject (readonly)

Returns the value of attribute page_number.



2
3
4
# File 'lib/zarchitect/paginator.rb', line 2

def page_number
  @page_number
end

#posts_per_pageObject (readonly)

Returns the value of attribute posts_per_page.



2
3
4
# File 'lib/zarchitect/paginator.rb', line 2

def posts_per_page
  @posts_per_page
end

#rangeObject (readonly)

Returns the value of attribute range.



2
3
4
# File 'lib/zarchitect/paginator.rb', line 2

def range
  @range
end

Instance Method Details

#nextObject



24
25
26
27
28
29
30
31
32
# File 'lib/zarchitect/paginator.rb', line 24

def next
  if @curr_page < @page_number
    @curr_page += 1
    update_range
  else
    GPI.print "Warning: paginator attempted to exceed total page number",
      GPI::CLU.check_option('v')
  end
end

#paginates?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/zarchitect/paginator.rb', line 34

def paginates?
  @page_number > 1
end

#url(n) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/zarchitect/paginator.rb', line 16

def url(n)
  if n == 1
    return File.join(@base_url, "index.html")
  else
    return File.join(@base_url, "index-#{n}.html")
  end
end