Class: LHS::Pagination
- Inherits:
-
Object
show all
- Defined in:
- lib/lhs/pagination.rb
Overview
Pagination is used to navigate paginateable collections
Constant Summary
collapse
- DEFAULT_LIMIT =
100
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Pagination.
9
10
11
|
# File 'lib/lhs/pagination.rb', line 9
def initialize(data)
self.data = data
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
7
8
9
|
# File 'lib/lhs/pagination.rb', line 7
def data
@data
end
|
Class Method Details
.page_to_offset(page, _limit) ⇒ Object
68
69
70
|
# File 'lib/lhs/pagination.rb', line 68
def self.page_to_offset(page, _limit)
page.to_i
end
|
Instance Method Details
#count ⇒ Object
as standard in Rails’ ActiveRecord count is not summing up, but using the number provided from data source
14
15
16
|
# File 'lib/lhs/pagination.rb', line 14
def count
total
end
|
#first_page ⇒ Object
44
45
46
|
# File 'lib/lhs/pagination.rb', line 44
def first_page
1
end
|
#last_page ⇒ Object
48
49
50
|
# File 'lib/lhs/pagination.rb', line 48
def last_page
total_pages
end
|
#limit ⇒ Object
22
23
24
|
# File 'lib/lhs/pagination.rb', line 22
def limit
data._raw[_record.limit_key.to_sym] || LHS::::DEFAULT_LIMIT
end
|
#limit_value ⇒ Object
60
61
62
|
# File 'lib/lhs/pagination.rb', line 60
def limit_value
limit
end
|
#next_offset ⇒ Object
36
37
38
|
# File 'lib/lhs/pagination.rb', line 36
def next_offset
raise 'to be implemented in subclass'
end
|
#next_page ⇒ Object
56
57
58
|
# File 'lib/lhs/pagination.rb', line 56
def next_page
current_page + 1
end
|
#offset ⇒ Object
Also known as:
current_page, start
26
27
28
|
# File 'lib/lhs/pagination.rb', line 26
def offset
data._raw[_record..to_sym].presence || 0
end
|
#pages_left ⇒ Object
32
33
34
|
# File 'lib/lhs/pagination.rb', line 32
def pages_left
total_pages - current_page
end
|
#prev_page ⇒ Object
52
53
54
|
# File 'lib/lhs/pagination.rb', line 52
def prev_page
current_page - 1
end
|
#total ⇒ Object
18
19
20
|
# File 'lib/lhs/pagination.rb', line 18
def total
data._raw[_record.total_key.to_sym]
end
|
#total_pages ⇒ Object
64
65
66
|
# File 'lib/lhs/pagination.rb', line 64
def total_pages
(total.to_f / limit).ceil
end
|