Class: Workarea::PagedArray

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#itemsObject (readonly)

Returns the value of attribute items.



3
4
5
# File 'lib/workarea/paged_array.rb', line 3

def items
  @items
end

#pageObject (readonly)

Returns the value of attribute page.



3
4
5
# File 'lib/workarea/paged_array.rb', line 3

def page
  @page
end

#per_pageObject (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

#totalObject (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_pageObject



29
30
31
# File 'lib/workarea/paged_array.rb', line 29

def current_page
  @page
end

#first_page?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/workarea/paged_array.rb', line 17

def first_page?
  page == 1
end

#last_page?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/workarea/paged_array.rb', line 21

def last_page?
  current_page == total_pages
end

#total_countObject



33
34
35
# File 'lib/workarea/paged_array.rb', line 33

def total_count
  total
end

#total_pagesObject



25
26
27
# File 'lib/workarea/paged_array.rb', line 25

def total_pages
  (total / per_page.to_f).ceil
end