Class: PaginatedArray
- Inherits:
-
Array
- Object
- Array
- PaginatedArray
- Defined in:
- lib/paginated_array.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
readonly
Returns the value of attribute current_page.
-
#per_page ⇒ Object
readonly
Returns the value of attribute per_page.
-
#total_count ⇒ Object
readonly
Returns the value of attribute total_count.
Instance Method Summary collapse
-
#initialize(total_count, current_page, per_page) ⇒ PaginatedArray
constructor
A new instance of PaginatedArray.
- #next_page ⇒ Object
- #previous_page ⇒ Object
- #total_page ⇒ Object
Constructor Details
#initialize(total_count, current_page, per_page) ⇒ PaginatedArray
Returns a new instance of PaginatedArray.
5 6 7 8 9 10 |
# File 'lib/paginated_array.rb', line 5 def initialize(total_count, current_page, per_page) @total_count = total_count @current_page = current_page @per_page = per_page super() end |
Instance Attribute Details
#current_page ⇒ Object (readonly)
Returns the value of attribute current_page.
2 3 4 |
# File 'lib/paginated_array.rb', line 2 def current_page @current_page end |
#per_page ⇒ Object (readonly)
Returns the value of attribute per_page.
2 3 4 |
# File 'lib/paginated_array.rb', line 2 def per_page @per_page end |
#total_count ⇒ Object (readonly)
Returns the value of attribute total_count.
2 3 4 |
# File 'lib/paginated_array.rb', line 2 def total_count @total_count end |
Instance Method Details
#next_page ⇒ Object
16 17 18 19 |
# File 'lib/paginated_array.rb', line 16 def next_page next_page = current_page + 1 next_page <= total_page ? next_page : false end |
#previous_page ⇒ Object
21 22 23 24 |
# File 'lib/paginated_array.rb', line 21 def previous_page previous_page = current_page - 1 previous_page > 0 ? previous_page : false end |
#total_page ⇒ Object
12 13 14 |
# File 'lib/paginated_array.rb', line 12 def total_page (total_count.fdiv(per_page)).ceil end |