Class: Webby::Paginator::Page
- Inherits:
-
Object
- Object
- Webby::Paginator::Page
- Includes:
- Enumerable
- Defined in:
- lib/webby/stelan/paginator.rb
Overview
Page object
Retrieves items for a page and provides metadata about the position of the page in the paginator
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#pager ⇒ Object
readonly
Returns the value of attribute pager.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#==(other) ⇒ Object
:nodoc:.
- #each(&block) ⇒ Object
-
#first_item_number ⇒ Object
The “item number” of the first item on this page.
-
#initialize(pager, number, select) ⇒ Page
constructor
:nodoc:.
-
#items ⇒ Object
Retrieve the items for this page * Caches.
-
#last_item_number ⇒ Object
The “item number” of the last item on this page.
-
#method_missing(meth, *args, &block) ⇒ Object
:nodoc:.
-
#next ⇒ Object
Get next page (if possible).
-
#next? ⇒ Boolean
Checks to see if there’s a page after this one.
-
#prev ⇒ Object
Get previous page (if possible).
-
#prev? ⇒ Boolean
Checks to see if there’s a page before this one.
Methods included from Enumerable
Constructor Details
#initialize(pager, number, select) ⇒ Page
:nodoc:
82 83 84 85 86 87 88 89 |
# File 'lib/webby/stelan/paginator.rb', line 82 def initialize(pager, number, select) #:nodoc: @pager, @number = pager, number @offset = (number - 1) * pager.per_page @select = select @pager.resource.number = (number == 1 ? nil : number) @url = @pager.resource.url end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
:nodoc:
139 140 141 142 143 144 145 |
# File 'lib/webby/stelan/paginator.rb', line 139 def method_missing(meth, *args, &block) #:nodoc: if @pager.respond_to?(meth) @pager.__send__(meth, *args, &block) else super end end |
Instance Attribute Details
#number ⇒ Object (readonly)
Returns the value of attribute number.
80 81 82 |
# File 'lib/webby/stelan/paginator.rb', line 80 def number @number end |
#pager ⇒ Object (readonly)
Returns the value of attribute pager.
80 81 82 |
# File 'lib/webby/stelan/paginator.rb', line 80 def pager @pager end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
80 81 82 |
# File 'lib/webby/stelan/paginator.rb', line 80 def url @url end |
Instance Method Details
#==(other) ⇒ Object
:nodoc:
131 132 133 |
# File 'lib/webby/stelan/paginator.rb', line 131 def ==(other) #:nodoc: @pager == other.pager && self.number == other.number end |
#each(&block) ⇒ Object
135 136 137 |
# File 'lib/webby/stelan/paginator.rb', line 135 def each(&block) items.each(&block) end |
#first_item_number ⇒ Object
The “item number” of the first item on this page
118 119 120 |
# File 'lib/webby/stelan/paginator.rb', line 118 def first_item_number 1 + @offset end |
#items ⇒ Object
Retrieve the items for this page
-
Caches
93 94 95 |
# File 'lib/webby/stelan/paginator.rb', line 93 def items @items ||= @select.call end |
#last_item_number ⇒ Object
The “item number” of the last item on this page
123 124 125 126 127 128 129 |
# File 'lib/webby/stelan/paginator.rb', line 123 def last_item_number if next? @offset + @pager.per_page else @pager.count end end |
#next ⇒ Object
Get next page (if possible)
113 114 115 |
# File 'lib/webby/stelan/paginator.rb', line 113 def next @pager.page(@number + 1) if next? end |
#next? ⇒ Boolean
Checks to see if there’s a page after this one
108 109 110 |
# File 'lib/webby/stelan/paginator.rb', line 108 def next? @number < @pager.number_of_pages end |
#prev ⇒ Object
Get previous page (if possible)
103 104 105 |
# File 'lib/webby/stelan/paginator.rb', line 103 def prev @pager.page(@number - 1) if prev? end |
#prev? ⇒ Boolean
Checks to see if there’s a page before this one
98 99 100 |
# File 'lib/webby/stelan/paginator.rb', line 98 def prev? @number > 1 end |