Class: Checkoff::Sections
- Inherits:
-
Object
- Object
- Checkoff::Sections
- Extended by:
- CacheMethod::ClassMethods, Forwardable
- Defined in:
- lib/checkoff/sections.rb
Overview
Query different sections of Asana projects
Constant Summary collapse
Instance Attribute Summary collapse
- #my_tasks ⇒ Checkoff::MyTasks readonly
- #projects ⇒ Checkoff::Projects readonly
- #time ⇒ Class<Time> readonly
- #workspaces ⇒ Checkoff::Workspaces readonly
Instance Method Summary collapse
-
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config: config).client, projects: Checkoff::Projects.new(config: config, client: client), workspaces: Checkoff::Workspaces.new(config: config, client: client), time: Time) ⇒ Sections
constructor
A new instance of Sections.
- #previous_section(section) ⇒ Asana::Resources::Section?
- #section_by_gid(gid) ⇒ Asana::Resources::Section
- #section_key(name) ⇒ String?
-
#section_or_raise(workspace_name, project_name, section_name, extra_section_fields: []) ⇒ Asana::Resources::Section
@sg-ignore.
-
#section_task_names(workspace_name, project_name, section_name) ⇒ Array<String>
Pulls just names of tasks from a given section.
-
#sections_by_project_gid(project_gid, extra_fields: []) ⇒ Enumerable<Asana::Resources::Section>
Returns a list of Asana API section objects for a given project GID.
-
#sections_or_raise(workspace_name, project_name, extra_fields: []) ⇒ Enumerable<Asana::Resources::Section>
Returns a list of Asana API section objects for a given project.
-
#tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
XXX: Rename to section_tasks.
-
#tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) ⇒ Hash{[String, nil] => Enumerable<Asana::Resources::Task>}
Given a workspace name and project name, then provide a Hash of tasks with section name -> task list of the uncompleted tasks.
- #tasks_by_section_gid(section_gid, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
Constructor Details
#initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config: config).client, projects: Checkoff::Projects.new(config: config, client: client), workspaces: Checkoff::Workspaces.new(config: config, client: client), time: Time) ⇒ Sections
Returns a new instance of Sections.
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/checkoff/sections.rb', line 38 def initialize(config: Checkoff::Internal::ConfigLoader.load(:asana), client: Checkoff::Clients.new(config: config).client, projects: Checkoff::Projects.new(config: config, client: client), workspaces: Checkoff::Workspaces.new(config: config, client: client), time: Time) @projects = projects @workspaces = workspaces @my_tasks = Checkoff::MyTasks.new(config: config, projects: projects, client: client) @client = client @time = time end |
Instance Attribute Details
#my_tasks ⇒ Checkoff::MyTasks (readonly)
31 32 33 |
# File 'lib/checkoff/sections.rb', line 31 def my_tasks @my_tasks end |
#projects ⇒ Checkoff::Projects (readonly)
22 23 24 |
# File 'lib/checkoff/sections.rb', line 22 def projects @projects end |
#time ⇒ Class<Time> (readonly)
28 29 30 |
# File 'lib/checkoff/sections.rb', line 28 def time @time end |
#workspaces ⇒ Checkoff::Workspaces (readonly)
25 26 27 |
# File 'lib/checkoff/sections.rb', line 25 def workspaces @workspaces end |
Instance Method Details
#previous_section(section) ⇒ Asana::Resources::Section?
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/checkoff/sections.rb', line 180 def previous_section(section) sections = sections_by_project_gid(section.project.fetch('gid')) # @type [Array<Asana::Resources::Section>] sections = sections.to_a index = sections.find_index { |s| s.gid == section.gid } return nil if index.nil? || index.zero? sections[index - 1] end |
#section_by_gid(gid) ⇒ Asana::Resources::Section
196 197 198 199 200 |
# File 'lib/checkoff/sections.rb', line 196 def section_by_gid(gid) = {} Asana::Resources::Section.new(parse(client.get("/sections/#{gid}", options: )).first, client: client) end |
#section_key(name) ⇒ String?
170 171 172 173 174 175 |
# File 'lib/checkoff/sections.rb', line 170 def section_key(name) inbox_section_names = ['(no section)', 'Untitled section', 'Inbox', 'Recently assigned'] return nil if inbox_section_names.include?(name) name end |
#section_or_raise(workspace_name, project_name, section_name, extra_section_fields: []) ⇒ Asana::Resources::Section
@sg-ignore
154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/checkoff/sections.rb', line 154 def section_or_raise(workspace_name, project_name, section_name, extra_section_fields: []) s = section(workspace_name, project_name, section_name, extra_section_fields: extra_section_fields) if s.nil? valid_sections = sections_or_raise(workspace_name, project_name, extra_fields: extra_section_fields).map(&:name) raise "Could not find section #{section_name.inspect} under project #{project_name.inspect} " \ "under workspace #{workspace_name.inspect}. Valid sections: #{valid_sections.inspect}" end s end |
#section_task_names(workspace_name, project_name, section_name) ⇒ Array<String>
Pulls just names of tasks from a given section.
141 142 143 144 |
# File 'lib/checkoff/sections.rb', line 141 def section_task_names(workspace_name, project_name, section_name) task_array = tasks(workspace_name, project_name, section_name) task_array.map(&:name) end |
#sections_by_project_gid(project_gid, extra_fields: []) ⇒ Enumerable<Asana::Resources::Section>
Returns a list of Asana API section objects for a given project GID
69 70 71 72 73 |
# File 'lib/checkoff/sections.rb', line 69 def sections_by_project_gid(project_gid, extra_fields: []) fields = %w[name] + extra_fields client.sections.get_sections_for_project(project_gid: project_gid, options: { fields: fields }) end |
#sections_or_raise(workspace_name, project_name, extra_fields: []) ⇒ Enumerable<Asana::Resources::Section>
Returns a list of Asana API section objects for a given project
58 59 60 61 |
# File 'lib/checkoff/sections.rb', line 58 def sections_or_raise(workspace_name, project_name, extra_fields: []) project = project_or_raise(workspace_name, project_name) sections_by_project_gid(project.gid, extra_fields: extra_fields) end |
#tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
XXX: Rename to section_tasks
Pulls task objects from a specified section
123 124 125 126 127 128 129 130 131 132 |
# File 'lib/checkoff/sections.rb', line 123 def tasks(workspace_name, project_name, section_name, only_uncompleted: true, extra_fields: []) section = section_or_raise(workspace_name, project_name, section_name) = projects. [:options][:fields] += extra_fields [:completed_since] = '9999-12-01' if only_uncompleted client.tasks.get_tasks(section: section.gid, **) end |
#tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) ⇒ Hash{[String, nil] => Enumerable<Asana::Resources::Task>}
Given a workspace name and project name, then provide a Hash of tasks with section name -> task list of the uncompleted tasks
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/checkoff/sections.rb', line 83 def tasks_by_section(workspace_name, project_name, only_uncompleted: true, extra_fields: []) raise ArgumentError, 'Provided nil workspace name' if workspace_name.nil? raise ArgumentError, 'Provided nil project name' if project_name.nil? project = project_or_raise(workspace_name, project_name) if project_name == :my_tasks my_tasks.tasks_by_section_for_my_tasks(project, only_uncompleted: only_uncompleted, extra_fields: extra_fields) else tasks_by_section_for_project(project, only_uncompleted: only_uncompleted, extra_fields: extra_fields) end end |
#tasks_by_section_gid(section_gid, only_uncompleted: true, extra_fields: []) ⇒ Enumerable<Asana::Resources::Task>
103 104 105 106 107 108 109 110 |
# File 'lib/checkoff/sections.rb', line 103 def tasks_by_section_gid(section_gid, only_uncompleted: true, extra_fields: []) = projects. [:options][:fields] += extra_fields [:completed_since] = '9999-12-01' if only_uncompleted client.tasks.get_tasks(section: section_gid, **) end |