Class: PaginatedArray

Inherits:
Array
  • Object
show all
Defined in:
lib/paginated_array.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pageObject (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_pageObject (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_countObject (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_pageObject



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_pageObject



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_pageObject



12
13
14
# File 'lib/paginated_array.rb', line 12

def total_page
  (total_count.fdiv(per_page)).ceil
end