Class: Alula::Pagination

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(meta_page_obj) ⇒ Pagination

Returns a new instance of Pagination.



5
6
7
8
9
# File 'lib/alula/pagination.rb', line 5

def initialize(meta_page_obj)
  @total = meta_page_obj['total']
  @number = meta_page_obj['number']
  @size = meta_page_obj['size']
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



3
4
5
# File 'lib/alula/pagination.rb', line 3

def number
  @number
end

#sizeObject (readonly)

Returns the value of attribute size.



3
4
5
# File 'lib/alula/pagination.rb', line 3

def size
  @size
end

#totalObject (readonly)

Returns the value of attribute total.



3
4
5
# File 'lib/alula/pagination.rb', line 3

def total
  @total
end

Instance Method Details

#has_next?Boolean

Returns:

  • (Boolean)


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

def has_next?
  number < page_count
end

#has_prev?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/alula/pagination.rb', line 15

def has_prev?
  number > 1
end

#page_countObject



19
20
21
22
23
# File 'lib/alula/pagination.rb', line 19

def page_count
  (total.to_f / size.to_f).ceil
rescue ZeroDivisionError
  0
end