Class: LHS::Pagination::Base
- Inherits:
-
Object
- Object
- LHS::Pagination::Base
show all
- Defined in:
- lib/lhs/pagination/base.rb
Constant Summary
collapse
- DEFAULT_LIMIT =
100
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(data) ⇒ Base
Returns a new instance of Base.
14
15
16
|
# File 'lib/lhs/pagination/base.rb', line 14
def initialize(data)
self.data = data
end
|
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
12
13
14
|
# File 'lib/lhs/pagination/base.rb', line 12
def data
@data
end
|
Class Method Details
.page_to_offset(page, _limit) ⇒ Object
86
87
88
|
# File 'lib/lhs/pagination/base.rb', line 86
def self.page_to_offset(page, _limit)
page.to_i
end
|
Instance Method Details
#current_page ⇒ Object
46
47
48
|
# File 'lib/lhs/pagination/base.rb', line 46
def current_page
end
|
#first_page ⇒ Object
50
51
52
|
# File 'lib/lhs/pagination/base.rb', line 50
def first_page
1
end
|
#last_page ⇒ Object
54
55
56
|
# File 'lib/lhs/pagination/base.rb', line 54
def last_page
total_pages
end
|
#limit ⇒ Object
25
26
27
|
# File 'lib/lhs/pagination/base.rb', line 25
def limit
data._raw.dig(*_record.limit_key(:body)) || DEFAULT_LIMIT
end
|
#limit_value ⇒ Object
78
79
80
|
# File 'lib/lhs/pagination/base.rb', line 78
def limit_value
limit
end
|
#next? ⇒ Boolean
62
63
64
|
# File 'lib/lhs/pagination/base.rb', line 62
def next?
data._raw[:next].present?
end
|
#next_offset(_step = 1) ⇒ Object
42
43
44
|
# File 'lib/lhs/pagination/base.rb', line 42
def next_offset(_step = 1)
raise 'to be implemented in subclass'
end
|
#next_page ⇒ Object
74
75
76
|
# File 'lib/lhs/pagination/base.rb', line 74
def next_page
current_page + 1
end
|
#offset ⇒ Object
Also known as:
start
29
30
31
|
# File 'lib/lhs/pagination/base.rb', line 29
def offset
data._raw.dig(*_record.(:body)) || self.class::DEFAULT_OFFSET
end
|
#pages_left ⇒ Object
34
35
36
|
# File 'lib/lhs/pagination/base.rb', line 34
def pages_left
total_pages - current_page
end
|
#pages_left? ⇒ Boolean
38
39
40
|
# File 'lib/lhs/pagination/base.rb', line 38
def pages_left?
pages_left > 0
end
|
#parallel? ⇒ Boolean
58
59
60
|
# File 'lib/lhs/pagination/base.rb', line 58
def parallel?
true
end
|
#prev_page ⇒ Object
70
71
72
|
# File 'lib/lhs/pagination/base.rb', line 70
def prev_page
current_page - 1
end
|
#previous? ⇒ Boolean
66
67
68
|
# File 'lib/lhs/pagination/base.rb', line 66
def previous?
data._raw[:previous].present?
end
|
#total ⇒ Object
Also known as:
count
18
19
20
|
# File 'lib/lhs/pagination/base.rb', line 18
def total
data._raw.dig(*_record.total_key) || 0
end
|
#total_pages ⇒ Object
82
83
84
|
# File 'lib/lhs/pagination/base.rb', line 82
def total_pages
(total.to_f / limit).ceil
end
|