Class: Ramaze::Helper::Paginate::Paginator::ArrayPager
- Inherits:
-
Object
- Object
- Ramaze::Helper::Paginate::Paginator::ArrayPager
- Includes:
- Enumerable
- Defined in:
- lib/ramaze/helper/paginate.rb
Overview
Wrapper for Array to behave like the Sequel pagination
Direct Known Subclasses
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.
241 242 243 244 |
# File 'lib/ramaze/helper/paginate.rb', line 241 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
259 260 261 |
# File 'lib/ramaze/helper/paginate.rb', line 259 def current_page @page end |
#each(&block) ⇒ Object
279 280 281 282 283 284 285 |
# File 'lib/ramaze/helper/paginate.rb', line 279 def each(&block) from = ((@page - 1) * @limit) to = from + @limit a = @array[from...to] || [] a.each(&block) end |
#empty? ⇒ Boolean
250 251 252 |
# File 'lib/ramaze/helper/paginate.rb', line 250 def empty? @array.empty? end |
#first_page? ⇒ Boolean
271 272 273 |
# File 'lib/ramaze/helper/paginate.rb', line 271 def first_page? @page <= 1 end |
#last_page? ⇒ Boolean
275 276 277 |
# File 'lib/ramaze/helper/paginate.rb', line 275 def last_page? page_count == @page end |
#next_page ⇒ Object
263 264 265 |
# File 'lib/ramaze/helper/paginate.rb', line 263 def next_page page_count == @page ? nil : @page + 1 end |
#page_count ⇒ Object
254 255 256 257 |
# File 'lib/ramaze/helper/paginate.rb', line 254 def page_count pages, rest = size.divmod(@limit) rest == 0 ? pages : pages + 1 end |
#prev_page ⇒ Object
267 268 269 |
# File 'lib/ramaze/helper/paginate.rb', line 267 def prev_page @page <= 1 ? nil : @page - 1 end |
#size ⇒ Object
246 247 248 |
# File 'lib/ramaze/helper/paginate.rb', line 246 def size @array.size end |