Class: Pagelux::QueryPaginator::PaginationData
- Inherits:
-
Object
- Object
- Pagelux::QueryPaginator::PaginationData
- Defined in:
- lib/pagelux/query_paginator.rb
Instance Attribute Summary collapse
-
#limit ⇒ Object
readonly
Returns the value of attribute limit.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(page = nil, limit = nil, query_total) ⇒ PaginationData
constructor
A new instance of PaginationData.
- #last_page ⇒ Object
- #normalize_page(n) ⇒ Object
Constructor Details
#initialize(page = nil, limit = nil, query_total) ⇒ PaginationData
Returns a new instance of PaginationData.
35 36 37 38 39 |
# File 'lib/pagelux/query_paginator.rb', line 35 def initialize(page=nil, limit=nil, query_total) @total = query_total @limit = (limit || self.class.default_limit).to_i @page = normalize_page(page) end |
Instance Attribute Details
#limit ⇒ Object (readonly)
Returns the value of attribute limit.
33 34 35 |
# File 'lib/pagelux/query_paginator.rb', line 33 def limit @limit end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
33 34 35 |
# File 'lib/pagelux/query_paginator.rb', line 33 def page @page end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
33 34 35 |
# File 'lib/pagelux/query_paginator.rb', line 33 def total @total end |
Class Method Details
.default_limit ⇒ Object
45 46 47 |
# File 'lib/pagelux/query_paginator.rb', line 45 def self.default_limit 100 end |
.default_page ⇒ Object
41 42 43 |
# File 'lib/pagelux/query_paginator.rb', line 41 def self.default_page 1 end |
Instance Method Details
#last_page ⇒ Object
56 57 58 |
# File 'lib/pagelux/query_paginator.rb', line 56 def last_page (total/limit.to_f).ceil end |
#normalize_page(n) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/pagelux/query_paginator.rb', line 49 def normalize_page(n) n = (n || self.class.default_page).to_i n = n > last_page ? last_page : n n = self.class.default_page if n < self.class.default_page n end |