Class: Hockey::PagingArray

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

Direct Known Subclasses

OrderedPagingArray

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializePagingArray

Returns a new instance of PagingArray.



20
21
22
23
# File 'lib/hockeyhelper/paging_array.rb', line 20

def initialize
  super
  @per_page = 25
end

Instance Attribute Details

#current_pageObject (readonly)

Returns the value of attribute current_page.



6
7
8
# File 'lib/hockeyhelper/paging_array.rb', line 6

def current_page
  @current_page
end

#per_pageObject (readonly)

25



7
8
9
# File 'lib/hockeyhelper/paging_array.rb', line 7

def per_page
  @per_page
end

#total_entriesObject (readonly)

Returns the value of attribute total_entries.



8
9
10
# File 'lib/hockeyhelper/paging_array.rb', line 8

def total_entries
  @total_entries
end

#total_pagesObject (readonly)

Returns the value of attribute total_pages.



9
10
11
# File 'lib/hockeyhelper/paging_array.rb', line 9

def total_pages
  @total_pages
end

Class Method Details

.paginate(with: [], page: 1) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/hockeyhelper/paging_array.rb', line 11

def self.paginate(with: [], page: 1)
  obj = self.new
  obj.replace(with[(page - 1) * obj.per_page, obj.per_page])
  obj.update_page_with(page, with.size)
  obj
rescue
  raise PageRangeError, 'your specified page is out of range in array'
end

Instance Method Details

#update_page(hashobj) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/hockeyhelper/paging_array.rb', line 25

def update_page(hashobj)
  @current_page  = hashobj['current_page'].to_i
  @total_entries = hashobj['total_entries'].to_i
  @total_pages   = hashobj['total_pages'].to_i

  self
end

#update_page_with(page, size) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/hockeyhelper/paging_array.rb', line 33

def update_page_with(page, size)
  @current_page = page
  @total_entries = size
  @total_pages = (size / @per_page) + 1

  self
end