Class: Aviary::Paginator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(per_page) ⇒ Paginator

Returns a new instance of Paginator.



8
9
10
11
12
13
# File 'lib/aviary/paginator.rb', line 8

def initialize(per_page)
  @per_page     = per_page
  @current_page = 1
  @first_page   = 1
  @last_page    = ImageHost.count / self.per_page
end

Instance Attribute Details

#current_pageObject (readonly)

Number for the current page



4
5
6
# File 'lib/aviary/paginator.rb', line 4

def current_page
  @current_page
end

#first_pageObject (readonly)

Minimum number of pages



5
6
7
# File 'lib/aviary/paginator.rb', line 5

def first_page
  @first_page
end

#last_pageObject (readonly)

Maximum number of pages



6
7
8
# File 'lib/aviary/paginator.rb', line 6

def last_page
  @last_page
end

#per_pageObject (readonly)

Number of photos per page



3
4
5
# File 'lib/aviary/paginator.rb', line 3

def per_page
  @per_page
end

Instance Method Details

#next_pageObject

Get the page number for the next page.

Returns page number.



25
26
27
# File 'lib/aviary/paginator.rb', line 25

def next_page
  self.current_page + 1
end

#next_page!Object

Get the page number for the next page and increment the current_page.

Returns page number.



32
33
34
# File 'lib/aviary/paginator.rb', line 32

def next_page!
  @current_page = next_page
end

#next_page?Boolean

True if this is not the last page.

Returns boolean.

Returns:

  • (Boolean)


18
19
20
# File 'lib/aviary/paginator.rb', line 18

def next_page?
  self.current_page < self.last_page
end

#prev_pageObject

Get the page number for the previous page.

Returns page number.



46
47
48
# File 'lib/aviary/paginator.rb', line 46

def prev_page
  self.current_page - 1
end

#prev_page?Boolean

True if this is not the first page.

Returns boolean.

Returns:

  • (Boolean)


39
40
41
# File 'lib/aviary/paginator.rb', line 39

def prev_page?
  self.current_page > self.first_page
end

#query_optionsObject



50
51
52
# File 'lib/aviary/paginator.rb', line 50

def query_options
  {:limit => self.per_page, :offset => self.per_page * (self.current_page - 1)}
end