Sha256: 21aec4cf85888a465a9295e37c0b00b06608aa437857c86b1e474a12891621a0

Contents?: true

Size: 1.4 KB

Versions: 23

Compression:

Stored size: 1.4 KB

Contents

# frozen_string_literal: true

require 'forwardable'
require_relative 'projects'
require_relative 'workspaces'
require_relative 'clients'

module Checkoff
  # Query different sections of Asana 'My Tasks' projects
  class MyTasks
    MINUTE = 60
    LONG_CACHE_TIME = MINUTE * 15
    SHORT_CACHE_TIME = MINUTE * 5

    attr_reader :projects

    def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana),
                   projects: Checkoff::Projects.new(config: config))
      @config = config
      @projects = projects
    end

    # Given a 'My Tasks' project object, pull all tasks, then provide
    # a Hash of tasks with section name -> task list of the
    # uncompleted tasks.
    def tasks_by_section_for_my_tasks(project, extra_fields: [])
      raw_tasks = projects.tasks_from_project(project,
                                              extra_fields: extra_fields + ['assignee_section.name'])
      active_tasks = projects.active_tasks(raw_tasks)
      by_my_tasks_section(active_tasks)
    end

    # Given a list of tasks in 'My Tasks', pull a Hash of tasks with
    # section name -> task list
    def by_my_tasks_section(tasks)
      by_section = {}
      tasks.each do |task|
        assignee_section = task.assignee_section
        current_section = assignee_section.name
        by_section[current_section] ||= []
        by_section[current_section] << task
      end
      by_section
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
checkoff-0.31.0 lib/checkoff/my_tasks.rb
checkoff-0.30.0 lib/checkoff/my_tasks.rb
checkoff-0.29.4 lib/checkoff/my_tasks.rb
checkoff-0.29.3 lib/checkoff/my_tasks.rb
checkoff-0.29.2 lib/checkoff/my_tasks.rb
checkoff-0.29.1 lib/checkoff/my_tasks.rb
checkoff-0.29.0 lib/checkoff/my_tasks.rb
checkoff-0.28.0 lib/checkoff/my_tasks.rb
checkoff-0.27.0 lib/checkoff/my_tasks.rb
checkoff-0.26.1 lib/checkoff/my_tasks.rb
checkoff-0.26.0 lib/checkoff/my_tasks.rb
checkoff-0.25.0 lib/checkoff/my_tasks.rb
checkoff-0.24.1 lib/checkoff/my_tasks.rb
checkoff-0.24.0 lib/checkoff/my_tasks.rb
checkoff-0.23.0 lib/checkoff/my_tasks.rb
checkoff-0.22.0 lib/checkoff/my_tasks.rb
checkoff-0.21.0 lib/checkoff/my_tasks.rb
checkoff-0.20.0 lib/checkoff/my_tasks.rb
checkoff-0.19.2 lib/checkoff/my_tasks.rb
checkoff-0.19.1 lib/checkoff/my_tasks.rb