Class: Scale::Api::TaskList

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/scale/api/task_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client: nil, docs: [], limit: 99, offset: 0, has_more: false, params: {}) ⇒ TaskList

Returns a new instance of TaskList.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/scale/api/task_list.rb', line 11

def initialize(client: nil, docs: [], limit: 99, offset: 0, has_more: false, params: {})
  self.client = client
  self.docs = docs.map do |doc|
    ::Scale::Api::Tasks::BaseTask.new(doc, client)
  end

  self.limit = limit
  self.offset = offset
  self.has_more = has_more
  self.params = params # Used to get next page
end

Instance Attribute Details

#clientObject

Returns the value of attribute client.



9
10
11
# File 'lib/scale/api/task_list.rb', line 9

def client
  @client
end

#docsObject

Returns the value of attribute docs.



9
10
11
# File 'lib/scale/api/task_list.rb', line 9

def docs
  @docs
end

#has_moreObject

Returns the value of attribute has_more.



9
10
11
# File 'lib/scale/api/task_list.rb', line 9

def has_more
  @has_more
end

#limitObject

Returns the value of attribute limit.



9
10
11
# File 'lib/scale/api/task_list.rb', line 9

def limit
  @limit
end

#offsetObject

Returns the value of attribute offset.



9
10
11
# File 'lib/scale/api/task_list.rb', line 9

def offset
  @offset
end

#paramsObject

Returns the value of attribute params.



9
10
11
# File 'lib/scale/api/task_list.rb', line 9

def params
  @params
end

Instance Method Details

#has_more?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/scale/api/task_list.rb', line 23

def has_more?
  !!has_more
end

#next_pageObject



31
32
33
34
35
# File 'lib/scale/api/task_list.rb', line 31

def next_page
  next_page_params = params.dup
  params[:offset] = params[:limit] + params[:offset]
  Scale::Api::Tasks.new(client).list(params)
end

#pageObject



27
28
29
# File 'lib/scale/api/task_list.rb', line 27

def page
  (offset + (limit * 1)) / limit
end