checkoff 0.94.0 → 0.95.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3728a0da90fb49dedd232b05722fbb87f03789d3bf9bc15513e4fa4b88f9e6fc
4
- data.tar.gz: 16ce81c8b51905620414ff21f9469ce83c100a61985f355b8a27de20b7234b3c
3
+ metadata.gz: 31607f856925472f48fd4ae56a34d190bef6ea7105086b399e1f2755a0f1dfa5
4
+ data.tar.gz: 8af77b66a6a15caa5e5f3c5b46746f042d30d6ff56742845a6c537b3afe01d11
5
5
  SHA512:
6
- metadata.gz: d73466d69b7b116eb8c58c0053b7cf13cedf288477e7cc8862de091fdd183e5a84355e19841e09df003da9b44d2b87ac90a459845c9186737069002f5312e455
7
- data.tar.gz: 207d7d34ecdc3435892afe3b96860df2373e36067f8c75866f7b87d5a6f0aac0ebe89b0889b45d6a31ddec1ac6211f592fce4b657aa70ffad5e5c504deeea773
6
+ metadata.gz: 5da70b5bbbd6538afa7b7953dfff42ec6377afe959f224c548d8886e64b36f1c101425c1ee51e6fced39ed8b06baa5f3c0f1aa96e92078cfebf1e1949ae4c3c9
7
+ data.tar.gz: 93f0ae0f4b00cf74cad672b3492b927ea72dc9f2dabd9b052e98da20098953848a69c55e79bcceda6ce6ce8c21fa77b0c08aff8f3378d0cb15a516f17e04a23e
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.94.0)
15
+ checkoff (0.95.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -50,6 +50,8 @@
50
50
  # def assignee; end
51
51
  # # @return [String, nil]
52
52
  # def html_notes; end
53
+ # # @return [Array<Hash{String => Hash{String => String}}>]
54
+ # def memberships; end
53
55
  # class << self
54
56
  # # @return [Asana::Resources::Task]
55
57
  # def create(client, assignee:, workspace:, name:); end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Checkoff
4
+ module Internal
5
+ # Builds on the standard API representation of an Asana task with some
6
+ # convenience keys.
7
+ class TaskHashes
8
+ # @param task [Asana::Resources::Task]
9
+ # @return [Hash]
10
+ def task_to_h(task)
11
+ # @type [Hash]
12
+ task_hash = task.to_h
13
+ task_hash['unwrapped'] = {}
14
+ unwrap_custom_fields(task_hash)
15
+ unwrap_memberships(task_hash)
16
+ task_hash['task'] = task.name
17
+ task_hash
18
+ end
19
+
20
+ private
21
+
22
+ # @param task_hash [Hash]
23
+ # @return [void]
24
+ def unwrap_custom_fields(task_hash)
25
+ unwrapped_custom_fields = task_hash.fetch('custom_fields', []).group_by do |cf|
26
+ cf['name']
27
+ end.transform_values(&:first)
28
+ task_hash['unwrapped']['custom_fields'] = unwrapped_custom_fields
29
+ end
30
+
31
+ # @param task_hash [Hash]
32
+ # @param resource [String]
33
+ # @param key [String]
34
+ #
35
+ # @return [void]
36
+ def unwrap_membership(task_hash, resource, key)
37
+ # @sg-ignore
38
+ # @type [Array<Hash>]
39
+ memberships = task_hash.fetch('memberships', [])
40
+ # @sg-ignore
41
+ # @type [Hash]
42
+ unwrapped = task_hash.fetch('unwrapped')
43
+ unwrapped["membership_by_#{resource}_#{key}"] = memberships.group_by do |membership|
44
+ membership[resource][key]
45
+ end.transform_values(&:first)
46
+ end
47
+
48
+ # @param task_hash [Hash]
49
+ # @return [void]
50
+ def unwrap_memberships(task_hash)
51
+ unwrap_membership(task_hash, 'section', 'gid')
52
+ unwrap_membership(task_hash, 'project', 'gid')
53
+ unwrap_membership(task_hash, 'project', 'name')
54
+ end
55
+ end
56
+ end
57
+ end
@@ -6,6 +6,7 @@ require_relative 'sections'
6
6
  require_relative 'workspaces'
7
7
  require_relative 'internal/config_loader'
8
8
  require_relative 'internal/task_timing'
9
+ require_relative 'internal/task_hashes'
9
10
  require 'asana'
10
11
 
11
12
  module Checkoff
@@ -145,6 +146,23 @@ module Checkoff
145
146
  end
146
147
  end
147
148
 
149
+ # Builds on the standard API representation of an Asana task with some
150
+ # convenience keys:
151
+ #
152
+ # <regular keys from API response>
153
+ # +
154
+ # unwrapped:
155
+ # membership_by_section_gid: Hash<String, Hash (membership)>
156
+ # membership_by_project_gid: Hash<String, Hash (membership)>
157
+ # membership_by_project_name: Hash<String, Hash (membership)>
158
+ # task: String (name)
159
+ #
160
+ # @param task [Asana::Resources::Task]
161
+ # @return [Hash]
162
+ def task_to_h(task)
163
+ task_hashes.task_to_h(task)
164
+ end
165
+
148
166
  private
149
167
 
150
168
  # @return [Checkoff::Internal::TaskTiming]
@@ -152,6 +170,11 @@ module Checkoff
152
170
  @task_timing ||= Checkoff::Internal::TaskTiming.new(time_class: @time_class)
153
171
  end
154
172
 
173
+ # @return [Checkoff::Internal::TaskHashes]
174
+ def task_hashes
175
+ @task_hashes ||= Checkoff::Internal::TaskHashes.new
176
+ end
177
+
155
178
  # @param workspace_name [String]
156
179
  # @param project_name [String, Symbol]
157
180
  # @param section_name [String, nil, Symbol<:unspecified>]
@@ -3,5 +3,5 @@
3
3
  # Command-line and gem client for Asana (unofficial)
4
4
  module Checkoff
5
5
  # Version of library
6
- VERSION = '0.94.0'
6
+ VERSION = '0.95.0'
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.94.0
4
+ version: 0.95.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
@@ -152,6 +152,7 @@ files:
152
152
  - lib/checkoff/internal/selector_classes/task.rb
153
153
  - lib/checkoff/internal/selector_classes/task/function_evaluator.rb
154
154
  - lib/checkoff/internal/selector_evaluator.rb
155
+ - lib/checkoff/internal/task_hashes.rb
155
156
  - lib/checkoff/internal/task_selector_evaluator.rb
156
157
  - lib/checkoff/internal/task_timing.rb
157
158
  - lib/checkoff/my_tasks.rb