Class: Workarea::PagedArray
- Inherits:
-
Array
- Object
- Array
- Workarea::PagedArray
- Defined in:
- lib/workarea/paged_array.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#page ⇒ Object
readonly
Returns the value of attribute page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Class Method Summary collapse
Instance Method Summary collapse
- #current_page ⇒ Object
- #first_page? ⇒ Boolean
-
#initialize(items = [], page = 1, per_page = 25, total = 0) ⇒ PagedArray
constructor
A new instance of PagedArray.
- #last_page? ⇒ Boolean
- #total_count ⇒ Object
- #total_pages ⇒ Object
Constructor Details
#initialize(items = [], page = 1, per_page = 25, total = 0) ⇒ PagedArray
Returns a new instance of PagedArray.
9 10 11 12 13 14 15 |
# File 'lib/workarea/paged_array.rb', line 9 def initialize(items = [], page = 1, per_page = 25, total = 0) @items = items @page = page.to_i @per_page = per_page.to_i @total = total.to_i super(items) end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
3 4 5 |
# File 'lib/workarea/paged_array.rb', line 3 def items @items end |
#page ⇒ Object (readonly)
Returns the value of attribute page.
3 4 5 |
# File 'lib/workarea/paged_array.rb', line 3 def page @page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
3 4 5 |
# File 'lib/workarea/paged_array.rb', line 3 def per_page @per_page end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
3 4 5 |
# File 'lib/workarea/paged_array.rb', line 3 def total @total end |
Class Method Details
.from(items, page, per_page, total) ⇒ Object
5 6 7 |
# File 'lib/workarea/paged_array.rb', line 5 def self.from(items, page, per_page, total) new(items, page, per_page, total) end |
Instance Method Details
#current_page ⇒ Object
29 30 31 |
# File 'lib/workarea/paged_array.rb', line 29 def current_page @page end |
#first_page? ⇒ Boolean
17 18 19 |
# File 'lib/workarea/paged_array.rb', line 17 def first_page? page == 1 end |
#last_page? ⇒ Boolean
21 22 23 |
# File 'lib/workarea/paged_array.rb', line 21 def last_page? current_page == total_pages end |
#total_count ⇒ Object
33 34 35 |
# File 'lib/workarea/paged_array.rb', line 33 def total_count total end |
#total_pages ⇒ Object
25 26 27 |
# File 'lib/workarea/paged_array.rb', line 25 def total_pages (total / per_page.to_f).ceil end |