Class: Statique::Paginator
- Inherits:
-
Object
- Object
- Statique::Paginator
- Defined in:
- lib/statique/paginator.rb
Instance Attribute Summary collapse
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#total_documents ⇒ Object
readonly
Returns the value of attribute total_documents.
-
#total_pages ⇒ Object
readonly
Returns the value of attribute total_pages.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(documents, path, page, statique = Statique.instance) ⇒ Paginator
constructor
A new instance of Paginator.
- #next_page ⇒ Object
- #next_page_path ⇒ Object
- #per_page ⇒ Object
- #previous_page ⇒ Object
- #previous_page_path ⇒ Object
Constructor Details
#initialize(documents, path, page, statique = Statique.instance) ⇒ Paginator
Returns a new instance of Paginator.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/statique/paginator.rb', line 11 def initialize(documents, path, page, statique = Statique.instance) @path, @page = path, [page.to_i, 1].max @statique = statique @total_documents = documents.size @offset = (self.class.per_page * (@page - 1)) @total_pages = (@total_documents.to_f / self.class.per_page).ceil @documents = documents[@offset, self.class.per_page] end |
Instance Attribute Details
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
5 6 7 |
# File 'lib/statique/paginator.rb', line 5 def documents @documents end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
5 6 7 |
# File 'lib/statique/paginator.rb', line 5 def page @page end |
#total_documents ⇒ Object (readonly)
Returns the value of attribute total_documents.
5 6 7 |
# File 'lib/statique/paginator.rb', line 5 def total_documents @total_documents end |
#total_pages ⇒ Object (readonly)
Returns the value of attribute total_pages.
5 6 7 |
# File 'lib/statique/paginator.rb', line 5 def total_pages @total_pages end |
Class Method Details
.per_page ⇒ Object
7 8 9 |
# File 'lib/statique/paginator.rb', line 7 def self.per_page @per_page ||= 10 end |
Instance Method Details
#next_page ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/statique/paginator.rb', line 39 def next_page page = [@total_pages, @page + 1].min if page == @page nil else page end end |
#next_page_path ⇒ Object
48 49 50 |
# File 'lib/statique/paginator.rb', line 48 def next_page_path page_path(next_page) end |
#per_page ⇒ Object
22 23 24 |
# File 'lib/statique/paginator.rb', line 22 def per_page self.class.per_page end |
#previous_page ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/statique/paginator.rb', line 26 def previous_page page = [1, @page - 1].max if page == @page nil else page end end |
#previous_page_path ⇒ Object
35 36 37 |
# File 'lib/statique/paginator.rb', line 35 def previous_page_path page_path(previous_page) end |