Created
August 14, 2012 21:30
-
-
Save bcm/3353209 to your computer and use it in GitHub Desktop.
Balanced pagination metadata
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/balanced/pager.rb b/lib/balanced/pager.rb | |
index 2338d0e..9150592 100644 | |
--- a/lib/balanced/pager.rb | |
+++ b/lib/balanced/pager.rb | |
@@ -34,17 +34,29 @@ module Balanced | |
load! unless @page | |
@page[:limit] | |
end | |
+ alias limit_value limit | |
def offset | |
load! unless @page | |
@page[:offset] | |
end | |
+ alias offset_value offset | |
def items | |
load! unless @page | |
@page[:items] | |
end | |
+ def current_page | |
+ (offset / limit) + 1 | |
+ end | |
+ | |
+ def num_pages | |
+ num = total / limit | |
+ num += 1 if total % limit > 0 | |
+ num | |
+ end | |
+ | |
# @return [Array] Iterates through the current page of records. | |
# @yield [record] | |
def each |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment