Class: Paged
Instance Method Summary
collapse
Constructor Details
#initialize(items, opts) ⇒ Paged
Returns a new instance of Paged.
4
5
6
7
8
9
|
# File 'lib/paged.rb', line 4
def initialize(items, opts)
raise ArgumentError.new ':page_size must be a positive number' unless opts[:page_size] and opts[:page_size] > 0
@items = items
@page_size = opts[:page_size]
@page = 0
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(symbol, *args, &block) ⇒ Object
36
37
38
|
# File 'lib/paged.rb', line 36
def method_missing(symbol, *args, &block)
page_of_items.send(symbol, *args, &block)
end
|
Instance Method Details
#next_page ⇒ Object
25
26
27
28
|
# File 'lib/paged.rb', line 25
def next_page
return if outside_bounds
page + 1 if page < total_pages
end
|
#page ⇒ Object
16
17
18
|
# File 'lib/paged.rb', line 16
def page
@page + 1
end
|
#page=(page) ⇒ Object
11
12
13
14
|
# File 'lib/paged.rb', line 11
def page=(page)
raise ArgumentError.new 'page must be a number' if not page.kind_of? Numeric
@page = page - 1
end
|
#previous_page ⇒ Object
20
21
22
23
|
# File 'lib/paged.rb', line 20
def previous_page
return if outside_bounds
page - 1 if page > 1
end
|
#respond_to?(symbol, include_private = false) ⇒ Boolean
30
31
32
|
# File 'lib/paged.rb', line 30
def respond_to?(symbol, include_private=false)
@items.respond_to? symbol, include_private
end
|