Class: Hudu::RequestPagination::PagingInfoPager

Inherits:
Object
  • Object
show all
Defined in:
lib/hudu/pagination.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page_size) ⇒ PagingInfoPager

Returns a new instance of PagingInfoPager.



12
13
14
15
# File 'lib/hudu/pagination.rb', line 12

def initialize(page_size)
  @page = 1
  @page_total = @page_size = page_size
end

Instance Attribute Details

#limitObject (readonly)

Returns the value of attribute limit.



11
12
13
# File 'lib/hudu/pagination.rb', line 11

def limit
  @limit
end

#offsetObject (readonly)

Returns the value of attribute offset.



11
12
13
# File 'lib/hudu/pagination.rb', line 11

def offset
  @offset
end

#totalObject (readonly)

Returns the value of attribute total.



11
12
13
# File 'lib/hudu/pagination.rb', line 11

def total
  @total
end

Class Method Details

.data(body) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/hudu/pagination.rb', line 32

def self.data(body) 
  # assume hash {"resource":[...]}, get first key and return array data
  k,v = body.first
  if v.is_a?(Array) || v.is_a?(Hash)
    v
  else
    body
  end
end

Instance Method Details

#more_pages?Boolean

Returns:

  • (Boolean)


27
28
29
30
# File 'lib/hudu/pagination.rb', line 27

def more_pages?
  # while full page we have next page
  @page_total == @page_size
end

#next_page!(body) ⇒ Object



21
22
23
24
25
# File 'lib/hudu/pagination.rb', line 21

def next_page!(body)
  @page += 1
  a = PagingInfoPager.data(body)
  @page_total = a.is_a?(Array) ? a.count : 1
end

#page_optionsObject



17
18
19
# File 'lib/hudu/pagination.rb', line 17

def page_options
  { page: @page }
end