Class: Harvesting::Models::Tasks

Inherits:
Base
  • Object
show all
Extended by:
Forwardable
Includes:
Enumerable
Defined in:
lib/harvesting/models/tasks.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#attributes, #client

Instance Method Summary collapse

Methods included from Enumerable

#each

Methods inherited from Base

attributed, #create, #save, #to_hash, #update

Constructor Details

#initialize(attrs, opts = {}) ⇒ Tasks

Returns a new instance of Tasks.



17
18
19
20
21
22
23
# File 'lib/harvesting/models/tasks.rb', line 17

def initialize(attrs, opts = {})
  super(attrs.reject {|k,v| k == "tasks" }, opts)
  @api_page = attrs
  @entries = attrs["tasks"].map do |entry|
    Task.new(entry, client: opts[:client])
  end
end

Instance Attribute Details

#entriesObject (readonly)

Returns the value of attribute entries.



15
16
17
# File 'lib/harvesting/models/tasks.rb', line 15

def entries
  @entries
end

Instance Method Details

#fetch_next_pageObject



38
39
40
41
42
# File 'lib/harvesting/models/tasks.rb', line 38

def fetch_next_page
  new_page = page + 1
  @entries += client.tasks(page: new_page).entries
  @attributes['page'] = new_page
end

#pageObject

def each

@entries.each_with_index do |time_entry, index|
  yield(time_entry)
end

end



30
31
32
# File 'lib/harvesting/models/tasks.rb', line 30

def page
  @attributes['page']
end

#sizeObject



34
35
36
# File 'lib/harvesting/models/tasks.rb', line 34

def size
  total_entries
end