Class: Checkoff::Subtasks
- Inherits:
-
Object
- Object
- Checkoff::Subtasks
- Extended by:
- Forwardable
- Defined in:
- lib/checkoff/subtasks.rb
Overview
Query different subtasks of Asana tasks
Constant Summary collapse
Instance Method Summary collapse
-
#all_subtasks_completed?(task) ⇒ Boolean
True if all subtasks of the task are completed.
-
#by_section(tasks) ⇒ Hash<[nil,String], Enumerable<Asana::Resources::Task>>
pulls a Hash of subtasks broken out by section.
-
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config)) ⇒ Subtasks
constructor
A new instance of Subtasks.
-
#raw_subtasks(task) ⇒ Object
Returns all subtasks, including section headers.
-
#subtask_section?(subtask) ⇒ Boolean
True if the subtask passed in represents a section in the subtasks.
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config)) ⇒ Subtasks
Returns a new instance of Subtasks.
16 17 18 19 |
# File 'lib/checkoff/subtasks.rb', line 16 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config)) @projects = projects end |
Instance Method Details
#all_subtasks_completed?(task) ⇒ Boolean
True if all subtasks of the task are completed
22 23 24 25 26 27 |
# File 'lib/checkoff/subtasks.rb', line 22 def all_subtasks_completed?(task) raw_subtasks = raw_subtasks(task) active_subtasks = @projects.active_tasks(raw_subtasks) # anything left should be a section active_subtasks.all? { |subtask| subtask_section?(subtask) } end |
#by_section(tasks) ⇒ Hash<[nil,String], Enumerable<Asana::Resources::Task>>
pulls a Hash of subtasks broken out by section
32 33 34 35 36 37 38 39 40 |
# File 'lib/checkoff/subtasks.rb', line 32 def by_section(tasks) current_section = nil by_section = { nil => [] } tasks.each do |task| current_section, by_section = file_task_by_section(current_section, by_section, task) end by_section end |
#raw_subtasks(task) ⇒ Object
Returns all subtasks, including section headers
43 44 45 46 47 |
# File 'lib/checkoff/subtasks.rb', line 43 def raw_subtasks(task) = projects. [:options][:fields] << 'is_rendered_as_separator' task.subtasks(**) end |
#subtask_section?(subtask) ⇒ Boolean
True if the subtask passed in represents a section in the subtasks
Note: expect this to be removed in a future version, as Asana is expected to move to the new-style way of representing sections as memberships with a separate API within a task.
55 56 57 |
# File 'lib/checkoff/subtasks.rb', line 55 def subtask_section?(subtask) subtask.is_rendered_as_separator end |