checkoff 0.99.0 → 0.101.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f0aa9c88e96e1094d284c59a9c7146ff72f393f2e16442c8e320b3253ab0221d
4
- data.tar.gz: 7f6021289d7fb0e331cb6b993b10307287c365d9a00d5fbe789e5b6c13972dad
3
+ metadata.gz: 6242a956ad83d3a1818be59711f4ba42040d7051dac2dd0ba2c8a2e5ed29f244
4
+ data.tar.gz: 515a08a90d20a58956256f76248f01d7a5fd52c6ac14e1fbd8215a6eb33dcc6d
5
5
  SHA512:
6
- metadata.gz: ab4476c149bf918e5d138f71a5d1c5df78192f3fa3fa13e8ef0e8a2d7c7198b34268a78ab14e6009237d3cf0113316f3ff91222d22893606c5ecc1ab31830d55
7
- data.tar.gz: 4f804bcfc9548b7106fcd80c5764da4250bf024e9dc7f1c2b95460078b89de3a238ba2b28f6d44188cd3fee074a0d348925ef780b751534a0f801f08b74fab24
6
+ metadata.gz: 8575f32ba5e2130117784cdf0b6e3f9bd40a11c918ffd99208457cd8dde84f7333da5ffc09096f520bccb28f6451da0605f3a3073002de89e8b9d75800371dfa
7
+ data.tar.gz: 037b01300963f231ba1401eb55beb47aff94deb9baab62c3d952876de3d3afc6d5a2c427bb717f5bdc0b8faa8cf3029bdd844de8d955ae3d600ebf9b2ee20835
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.99.0)
15
+ checkoff (0.101.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -63,6 +63,10 @@
63
63
  # # @return [String,nil]
64
64
  # def due_date; end
65
65
  # end
66
+ # class Portfolio
67
+ # # @return [Enumerable<Asana::Resources::Project>]
68
+ # def get_items(options = {}); end
69
+ # end
66
70
  # end
67
71
  # module Resources
68
72
  # class Workspace
@@ -114,7 +114,7 @@ module Checkoff
114
114
  end
115
115
  end
116
116
 
117
- # :ready_between_n_days function
117
+ # :ready_between_relative function
118
118
  class ReadyBetweenRelativePFunctionEvaluator < FunctionEvaluator
119
119
  FUNCTION_NAME = :ready_between_relative
120
120
 
@@ -134,24 +134,34 @@ module Checkoff
134
134
  #
135
135
  # @return [Boolean]
136
136
  def evaluate(task, beginning_num_days_from_now, end_num_days_from_now, ignore_dependencies: false)
137
+ ready_between_relative?(task,
138
+ beginning_num_days_from_now, end_num_days_from_now,
139
+ ignore_dependencies: ignore_dependencies)
140
+ end
141
+
142
+ private
143
+
144
+ # @param task [Asana::Resources::Task]
145
+ # @param beginning_num_days_from_now [Integer]
146
+ # @param end_num_days_from_now [Integer]
147
+ # @param ignore_dependencies [Boolean]
148
+ #
149
+ # @return [Boolean]
150
+ def ready_between_relative?(task,
151
+ beginning_num_days_from_now,
152
+ end_num_days_from_now,
153
+ ignore_dependencies: false)
137
154
  beginning_n_days_from_now_time = (Time.now + (beginning_num_days_from_now * 24 * 60 * 60))
138
155
  end_n_days_from_now_time = (Time.now + (end_num_days_from_now * 24 * 60 * 60))
139
156
 
140
157
  # @type [Date, Time, nil]
141
- task_date_or_time = @task_timing.date_or_time_field_by_name(task, :start) ||
142
- @task_timing.date_or_time_field_by_name(task, :due)
158
+ ready_date_or_time = @task_timing.date_or_time_field_by_name(task, :ready)
143
159
 
144
- return false if task_date_or_time.nil?
160
+ return false if ready_date_or_time.nil?
145
161
 
146
- # if time
147
- in_range = if task_date_or_time.is_a?(Time)
148
- task_date_or_time > beginning_n_days_from_now_time &&
149
- task_date_or_time <= end_n_days_from_now_time
150
- else
151
- # if date
152
- task_date_or_time > beginning_n_days_from_now_time.to_date &&
153
- task_date_or_time <= end_n_days_from_now_time.to_date
154
- end
162
+ in_range = ready_in_range?(ready_date_or_time,
163
+ beginning_n_days_from_now_time,
164
+ end_n_days_from_now_time)
155
165
 
156
166
  return false unless in_range
157
167
 
@@ -159,6 +169,17 @@ module Checkoff
159
169
 
160
170
  true
161
171
  end
172
+
173
+ # @param ready_date_or_time [Date, Time]
174
+ # @param start_time [Time]
175
+ # @param end_time [Time]
176
+ def ready_in_range?(ready_date_or_time, start_time, end_time)
177
+ if ready_date_or_time.is_a?(Time)
178
+ ready_date_or_time > start_time && ready_date_or_time <= end_time
179
+ else
180
+ ready_date_or_time > start_time.to_date && ready_date_or_time <= end_time.to_date
181
+ end
182
+ end
162
183
  end
163
184
 
164
185
  # :field_less_than_n_days_ago
@@ -373,6 +394,23 @@ module Checkoff
373
394
  limit_to_portfolio_gid: limit_to_portfolio_gid)
374
395
  end
375
396
  end
397
+
398
+ # :in_portfolio_named? function
399
+ class InPortfolioNamedFunctionEvaluator < FunctionEvaluator
400
+ FUNCTION_NAME = :in_portfolio_named?
401
+
402
+ def matches?
403
+ fn?(selector, FUNCTION_NAME)
404
+ end
405
+
406
+ # @param task [Asana::Resources::Task]
407
+ # @param portfolio_name [String]
408
+ #
409
+ # @return [Boolean]
410
+ def evaluate(task, portfolio_name)
411
+ @tasks.in_portfolio_named?(task, portfolio_name)
412
+ end
413
+ end
376
414
  end
377
415
  end
378
416
  end
@@ -59,6 +59,8 @@ module Checkoff
59
59
 
60
60
  return start_date_or_time(task) if field_name == :start
61
61
 
62
+ return start_date_or_time(task) || due_date_or_time(task) if field_name == :ready
63
+
62
64
  raise "Teach me how to handle field #{field_name}"
63
65
  end
64
66
  end
@@ -78,6 +78,16 @@ module Checkoff
78
78
  end
79
79
  cache_method :portfolio_by_gid, SHORT_CACHE_TIME
80
80
 
81
+ # @param workspace_name [String]
82
+ # @param portfolio_name [String]
83
+ #
84
+ # @return [Enumerable<Asana::Resources::Project>]
85
+ def projects_in_portfolio(workspace_name, portfolio_name)
86
+ portfolio = portfolio_or_raise(workspace_name, portfolio_name)
87
+ portfolio.get_items
88
+ end
89
+ cache_method :projects_in_portfolio, LONG_CACHE_TIME
90
+
81
91
  private
82
92
 
83
93
  # @return [Checkoff::Workspaces]
@@ -3,6 +3,7 @@
3
3
  # frozen_string_literal: true
4
4
 
5
5
  require_relative 'sections'
6
+ require_relative 'portfolios'
6
7
  require_relative 'workspaces'
7
8
  require_relative 'internal/config_loader'
8
9
  require_relative 'internal/task_timing'
@@ -26,6 +27,7 @@ module Checkoff
26
27
  # @param client [Asana::Client]
27
28
  # @param workspaces [Checkoff::Workspaces]
28
29
  # @param sections [Checkoff::Sections]
30
+ # @param portfolios [Checkoff::Portfolios]
29
31
  # @param time_class [Class<Time>]
30
32
  # @param date_class [Class<Date>]
31
33
  # @param asana_task [Class<Asana::Resources::Task>]
@@ -35,6 +37,8 @@ module Checkoff
35
37
  client: client),
36
38
  sections: Checkoff::Sections.new(config: config,
37
39
  client: client),
40
+ portfolios: Checkoff::Portfolios.new(config: config,
41
+ client: client),
38
42
  time_class: Time,
39
43
  date_class: Date,
40
44
  asana_task: Asana::Resources::Task)
@@ -44,6 +48,7 @@ module Checkoff
44
48
  @date_class = date_class
45
49
  @asana_task = asana_task
46
50
  @client = client
51
+ @portfolios = portfolios
47
52
  @workspaces = workspaces
48
53
  end
49
54
 
@@ -166,6 +171,21 @@ module Checkoff
166
171
  task_hashes.task_to_h(task)
167
172
  end
168
173
 
174
+ # @param task [Asana::Resources::Task]
175
+ # @param portfolio_name [String]
176
+ # @param workspace_name [String]
177
+ def in_portfolio_named?(task,
178
+ portfolio_name,
179
+ workspace_name: @workspaces.default_workspace.name)
180
+ portfolio_projects = @portfolios.projects_in_portfolio(workspace_name, portfolio_name)
181
+ task.memberships.any? do |membership|
182
+ project_gid = membership.fetch('project').fetch('gid')
183
+ portfolio_projects.any? do |portfolio_project|
184
+ portfolio_project.gid == project_gid
185
+ end
186
+ end
187
+ end
188
+
169
189
  private
170
190
 
171
191
  # @return [Checkoff::Internal::TaskTiming]
@@ -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.99.0'
6
+ VERSION = '0.101.0'
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkoff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.0
4
+ version: 0.101.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-10-27 00:00:00.000000000 Z
11
+ date: 2023-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport