Class: Harvesting::Models::Tasks
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Attributes inherited from Base
Instance Method Summary collapse
- #fetch_next_page ⇒ Object
-
#initialize(attrs, opts = {}) ⇒ Tasks
constructor
A new instance of Tasks.
-
#page ⇒ Object
def each @entries.each_with_index do |time_entry, index| yield(time_entry) end end.
- #size ⇒ Object
Methods included from Enumerable
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
#entries ⇒ Object (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_page ⇒ Object
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 |
#page ⇒ Object
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 |
#size ⇒ Object
34 35 36 |
# File 'lib/harvesting/models/tasks.rb', line 34 def size total_entries end |