Sha256: 633ebcb50156bbe269989e9479c33a6c3837d3e374659c05581d8f4158572304

Contents?: true

Size: 1.02 KB

Versions: 11

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require 'forwardable'

module Checkoff
  # Query different subtasks of Asana tasks
  class Subtasks
    MINUTE = 60
    LONG_CACHE_TIME = MINUTE * 15
    SHORT_CACHE_TIME = MINUTE * 5

    extend Forwardable

    def file_task_by_section(current_section, by_section, task)
      if task.name =~ /:$/
        current_section = task.name
        by_section[current_section] = []
      else
        by_section[current_section] ||= []
        by_section[current_section] << task
      end
      [current_section, by_section]
    end

    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

    # Returns all subtasks, including section headers
    def raw_subtasks(task)
      task.subtasks(projects.task_options)
    end
    cache_method :raw_subtasks, LONG_CACHE_TIME
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
checkoff-0.10.0 lib/checkoff/subtasks.rb
checkoff-0.9.0 lib/checkoff/subtasks.rb
checkoff-0.8.0 lib/checkoff/subtasks.rb
checkoff-0.7.0 lib/checkoff/subtasks.rb
checkoff-0.6.0 lib/checkoff/subtasks.rb
checkoff-0.5.5 lib/checkoff/subtasks.rb
checkoff-0.5.4 lib/checkoff/subtasks.rb
checkoff-0.5.3 lib/checkoff/subtasks.rb
checkoff-0.5.2 lib/checkoff/subtasks.rb
checkoff-0.5.1 lib/checkoff/subtasks.rb
checkoff-0.5.0 lib/checkoff/subtasks.rb