Class: Checkoff::Subtasks

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/checkoff/subtasks.rb

Overview

Query different subtasks of Asana tasks

Constant Summary collapse

MINUTE =
60
LONG_CACHE_TIME =
MINUTE * 15
SHORT_CACHE_TIME =
MINUTE * 5

Instance Method Summary collapse

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

Returns:

  • (Boolean)


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

Parameters:

  • tasks (Enumerable<Asana::Resources::Task>)

Returns:

  • (Hash<[nil,String], Enumerable<Asana::Resources::Task>>)


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)
  task_options = projects.task_options
  task_options[:options][:fields] << 'is_rendered_as_separator'
  task.subtasks(**task_options)
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.

Returns:

  • (Boolean)


55
56
57
# File 'lib/checkoff/subtasks.rb', line 55

def subtask_section?(subtask)
  subtask.is_rendered_as_separator
end