Class: Paged
Instance Method Summary
collapse
Constructor Details
#initialize(items, opts) ⇒ Paged
Returns a new instance of Paged.
6
7
8
9
10
11
|
# File 'lib/webbits/paged.rb', line 6
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
38
39
40
|
# File 'lib/webbits/paged.rb', line 38
def method_missing(symbol, *args, &block)
page_of_items.send(symbol, *args, &block)
end
|
Instance Method Details
#next_page ⇒ Object
27
28
29
30
|
# File 'lib/webbits/paged.rb', line 27
def next_page
return if outside_bounds
page + 1 if page < total_pages
end
|
#page ⇒ Object
18
19
20
|
# File 'lib/webbits/paged.rb', line 18
def page
@page + 1
end
|
#page=(page) ⇒ Object
13
14
15
16
|
# File 'lib/webbits/paged.rb', line 13
def page=(page)
raise ArgumentError.new 'page must be a number' if not page.kind_of? Numeric
@page = page - 1
end
|
#previous_page ⇒ Object
22
23
24
25
|
# File 'lib/webbits/paged.rb', line 22
def previous_page
return if outside_bounds
page - 1 if page > 1
end
|
#respond_to?(symbol, include_private = false) ⇒ Boolean
32
33
34
|
# File 'lib/webbits/paged.rb', line 32
def respond_to?(symbol, include_private=false)
@items.respond_to? symbol, include_private
end
|