Class: Ramaze::Helper::Paginate::Paginator::ArrayPager
- Includes:
- Enumerable
- Defined in:
- lib/ramaze/helper/paginate.rb
Overview
Wrapper for Array to behave like the Sequel pagination
Instance Method Summary collapse
- #current_page ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #first_page? ⇒ Boolean
-
#initialize(array, page, limit) ⇒ ArrayPager
constructor
A new instance of ArrayPager.
- #last_page? ⇒ Boolean
- #next_page ⇒ Object
- #page_count ⇒ Object
- #prev_page ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize(array, page, limit) ⇒ ArrayPager
Returns a new instance of ArrayPager.
181 182 183 184 |
# File 'lib/ramaze/helper/paginate.rb', line 181 def initialize(array, page, limit) @array, @page, @limit = array, page, limit @page = page_count if @page > page_count end |
Instance Method Details
#current_page ⇒ Object
199 200 201 |
# File 'lib/ramaze/helper/paginate.rb', line 199 def current_page @page end |
#each(&block) ⇒ Object
219 220 221 222 223 224 225 |
# File 'lib/ramaze/helper/paginate.rb', line 219 def each(&block) from = ((@page - 1) * @limit) to = from + @limit a = @array[from...to] || [] a.each(&block) end |
#empty? ⇒ Boolean
190 191 192 |
# File 'lib/ramaze/helper/paginate.rb', line 190 def empty? @array.empty? end |
#first_page? ⇒ Boolean
211 212 213 |
# File 'lib/ramaze/helper/paginate.rb', line 211 def first_page? @page <= 1 end |
#last_page? ⇒ Boolean
215 216 217 |
# File 'lib/ramaze/helper/paginate.rb', line 215 def last_page? page_count == @page end |
#next_page ⇒ Object
203 204 205 |
# File 'lib/ramaze/helper/paginate.rb', line 203 def next_page page_count == @page ? nil : @page + 1 end |
#page_count ⇒ Object
194 195 196 197 |
# File 'lib/ramaze/helper/paginate.rb', line 194 def page_count pages, rest = @array.size.divmod(@limit) rest == 0 ? pages : pages + 1 end |
#prev_page ⇒ Object
207 208 209 |
# File 'lib/ramaze/helper/paginate.rb', line 207 def prev_page @page <= 1 ? nil : @page - 1 end |
#size ⇒ Object
186 187 188 |
# File 'lib/ramaze/helper/paginate.rb', line 186 def size @array.size end |