Class: Tikkie::Api::Resources::List
- Inherits:
-
Base
- Object
- Base
- Tikkie::Api::Resources::List
show all
- Defined in:
- lib/tikkie/api/resources/list.rb
Overview
Base class for all list resources.
Instance Attribute Summary collapse
Attributes inherited from Base
#config, #options
Instance Method Summary
collapse
Methods inherited from Base
#delete, #load, #loaded?, #save
Constructor Details
#initialize(config, options = {}) ⇒ List
Returns a new instance of List.
12
13
14
15
16
|
# File 'lib/tikkie/api/resources/list.rb', line 12
def initialize(config, options = {})
@page_number = options.fetch(:page_number, 0)
@page_size = options.fetch(:page_size, 50)
super(config, options)
end
|
Instance Attribute Details
#page_number ⇒ Object
Returns the value of attribute page_number.
10
11
12
|
# File 'lib/tikkie/api/resources/list.rb', line 10
def page_number
@page_number
end
|
#page_size ⇒ Object
Returns the value of attribute page_size.
10
11
12
|
# File 'lib/tikkie/api/resources/list.rb', line 10
def page_size
@page_size
end
|
Instance Method Details
#next ⇒ Object
42
43
44
|
# File 'lib/tikkie/api/resources/list.rb', line 42
def next
self.class.new(config, options.merge(page_number: next_page)) if next_page?
end
|
#next_page ⇒ Object
26
27
28
|
# File 'lib/tikkie/api/resources/list.rb', line 26
def next_page
page_number + 1 if next_page?
end
|
#next_page? ⇒ Boolean
30
31
32
|
# File 'lib/tikkie/api/resources/list.rb', line 30
def next_page?
page_number && (page_number + 1) < total_pages
end
|
#previous ⇒ Object
46
47
48
|
# File 'lib/tikkie/api/resources/list.rb', line 46
def previous
self.class.new(config, options.merge(page_number: previous_page)) if previous_page?
end
|
#previous_page ⇒ Object
34
35
36
|
# File 'lib/tikkie/api/resources/list.rb', line 34
def previous_page
page_number - 1 if previous_page?
end
|
#previous_page? ⇒ Boolean
38
39
40
|
# File 'lib/tikkie/api/resources/list.rb', line 38
def previous_page?
page_number && page_number.positive?
end
|
#total_elements ⇒ Object
18
19
20
|
# File 'lib/tikkie/api/resources/list.rb', line 18
def total_elements
body[:totalElementCount].to_i
end
|
#total_pages ⇒ Object
22
23
24
|
# File 'lib/tikkie/api/resources/list.rb', line 22
def total_pages
(total_elements / BigDecimal(page_size)).ceil
end
|