class Checkoff::Subtasks

Query different subtasks of Asana tasks

Constants

LONG_CACHE_TIME
MINUTE
SHORT_CACHE_TIME

Attributes

projects[R]

Public Class Methods

new(config: Checkoff::ConfigLoader.load(:asana), projects: Checkoff::Projects.new(config: config)) click to toggle source
# File lib/checkoff/subtasks.rb, line 16
def initialize(config: Checkoff::ConfigLoader.load(:asana),
               projects: Checkoff::Projects.new(config: config))
  @projects = projects
end

Public Instance Methods

all_subtasks_completed?(task) click to toggle source

True if all subtasks of the task are completed

# 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) click to toggle source

pulls a Hash of subtasks broken out by section

# File lib/checkoff/subtasks.rb, line 30
def by_section(tasks)
  current_section = nil
  by_section = {}
  tasks.each do |task|
    current_section, by_section = file_task_by_section(current_section,
                                                       by_section, task)
  end
  by_section
end
raw_subtasks(task) click to toggle source

Returns all subtasks, including section headers

# File lib/checkoff/subtasks.rb, line 41
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) click to toggle source

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.

# File lib/checkoff/subtasks.rb, line 53
def subtask_section?(subtask)
  subtask.is_rendered_as_separator
end

Private Instance Methods

file_task_by_section(current_section, by_section, task) click to toggle source
# File lib/checkoff/subtasks.rb, line 61
def file_task_by_section(current_section, by_section, task)
  if subtask_section?(task)
    current_section = task.name
    by_section[current_section] = []
  else
    by_section[current_section] ||= []
    by_section[current_section] << task
  end
  [current_section, by_section]
end