checkoff 0.107.0 → 0.109.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: 9a3f9bd1bb8698f7f5a318fefbf79cc09cf17998177dfbbae762fb3be82e33d7
4
- data.tar.gz: 634e833fdb5f54c9f8a5e56411b4affb1a2d7384a1231a068bf77a8e37951088
3
+ metadata.gz: 199142d4090e6eb4196958d2c73958fefdfa864c0e7e69a5e8a589f198465b2e
4
+ data.tar.gz: aa0739c73ce5359fe1f965e4c46674bf3a7d79a603d7bcc683f671cd5e039fd9
5
5
  SHA512:
6
- metadata.gz: 950738387e7ecfe3652763452bca3dd79b39e3e8b8ca2618decacb77c04e6deb2d5b5680a272aacac5b46d97a75b53409a483bc339b13f8fd910c55d8ea0105a
7
- data.tar.gz: 176ac1780573b9fe89f97a75c9bddf4cc74b69833ee31ec60e0f684ef88a7ca4dafa5e5661e5c5aec78ce8e5392dc23e7b9f3022e7ef77c2e94b1cc5efd45300
6
+ metadata.gz: fce61c75d5175ad6c7ae37263f3065efc796dc496dd290616bd6cf1bb69518149231e6da378f6ee5573a8f17d1a55e73179da30e46820a61b237038b62483ff3
7
+ data.tar.gz: e7e2cadb887aaacb9fea39058bea689f087da8719ceba75931b768f92b170ca16bf2f93fe7731a18c4a5ebd00660ece4bfdf4f466f712bf98f7d74dc66d1e0b6
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.107.0)
15
+ checkoff (0.109.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -97,6 +97,26 @@ module Checkoff
97
97
  # rubocop:enable Style/OptionalBooleanParameter
98
98
  end
99
99
 
100
+ # :in_period? function
101
+ class InPeriodPFunctionEvaluator < FunctionEvaluator
102
+ def matches?
103
+ fn?(selector, :in_period?)
104
+ end
105
+
106
+ # @param _index [Integer]
107
+ def evaluate_arg?(_index)
108
+ false
109
+ end
110
+
111
+ # @param task [Asana::Resources::Task]
112
+ # @param field_name [Symbol] See Checksoff::Tasks#in_period?
113
+ # @param period [Symbol,Array<Symbol>] See Checkoff::Timing#in_period?
114
+ # @return [Boolean]
115
+ def evaluate(task, field_name, period)
116
+ @tasks.in_period?(task, field_name, period)
117
+ end
118
+ end
119
+
100
120
  # :unassigned function
101
121
  class UnassignedPFunctionEvaluator < FunctionEvaluator
102
122
  def matches?
@@ -153,58 +173,6 @@ module Checkoff
153
173
  end
154
174
  end
155
175
 
156
- # :field_less_than_n_days_ago
157
- class FieldLessThanNDaysAgoPFunctionEvaluator < FunctionEvaluator
158
- FUNCTION_NAME = :field_less_than_n_days_ago
159
-
160
- def matches?
161
- fn?(selector, FUNCTION_NAME)
162
- end
163
-
164
- def evaluate_arg?(_index)
165
- false
166
- end
167
-
168
- # @param task [Asana::Resources::Task]
169
- # @param field_name [Symbol]
170
- # @param num_days [Integer]
171
- #
172
- # @return [Boolean]
173
- def evaluate(task, field_name, num_days)
174
- @tasks.in_period?(task, field_name, [:less_than_n_days_ago, num_days])
175
- end
176
- end
177
-
178
- # :field_greater_than_or_equal_to_n_days_from_today
179
- class FieldGreaterThanOrEqualToNDaysFromTodayPFunctionEvaluator < FunctionEvaluator
180
- FUNCTION_NAME = :field_greater_than_or_equal_to_n_days_from_today
181
-
182
- def matches?
183
- fn?(selector, FUNCTION_NAME)
184
- end
185
-
186
- def evaluate_arg?(_index)
187
- false
188
- end
189
-
190
- # @param task [Asana::Resources::Task]
191
- # @param field_name [Symbol]
192
- # @param num_days [Integer]
193
- #
194
- # @return [Boolean]
195
- def evaluate(task, field_name, num_days)
196
- task_timing = Checkoff::Internal::TaskTiming.new
197
- date = task_timing.date_or_time_field_by_name(task, field_name)&.to_date
198
-
199
- return false if date.nil?
200
-
201
- # @sg-ignore
202
- n_days_from_today = Date.today + num_days
203
- # @sg-ignore
204
- date >= n_days_from_today
205
- end
206
- end
207
-
208
176
  # :custom_field_less_than_n_days_from_now function
209
177
  class CustomFieldLessThanNDaysFromNowFunctionEvaluator < FunctionEvaluator
210
178
  FUNCTION_NAME = :custom_field_less_than_n_days_from_now
@@ -30,13 +30,6 @@ module Checkoff
30
30
  @now_getter = now_getter
31
31
  end
32
32
 
33
- # @param date_or_time [Date,Time,nil]
34
- def now_or_before?(date_or_time)
35
- return true if date_or_time.nil?
36
-
37
- date_or_time.to_time < @now_getter.now
38
- end
39
-
40
33
  # @param date_or_time [Date,Time,nil]
41
34
  # @param period [Symbol,Array<(Symbol,Integer)>]
42
35
  #
@@ -54,8 +47,7 @@ module Checkoff
54
47
  period_name = period.first
55
48
  args = period[1..]
56
49
 
57
- # @sg-ignore
58
- return less_than_n_days_ago?(date_or_time, *args) if period_name == :less_than_n_days_ago
50
+ return compound_in_period?(date_or_time, period_name, *args)
59
51
  end
60
52
 
61
53
  raise "Teach me how to handle period #{period.inspect}"
@@ -63,6 +55,19 @@ module Checkoff
63
55
 
64
56
  private
65
57
 
58
+ # @param date_or_time [Date,Time,nil]
59
+ # @param num_days [Integer]
60
+ def greater_than_or_equal_to_n_days_from_today?(date_or_time, num_days)
61
+ return false if date_or_time.nil?
62
+
63
+ date = date_or_time.to_date
64
+
65
+ # @sg-ignore
66
+ n_days_from_today = @today_getter.today + num_days
67
+ # @sg-ignore
68
+ date >= n_days_from_today
69
+ end
70
+
66
71
  # @param date_or_time [Date,Time,nil]
67
72
  # @param num_days [Integer]
68
73
  def less_than_n_days_ago?(date_or_time, num_days)
@@ -93,6 +98,27 @@ module Checkoff
93
98
  date >= beginning_of_week && date <= end_of_week
94
99
  end
95
100
 
101
+ # @param date_or_time [Date,Time,nil]
102
+ def now_or_before?(date_or_time)
103
+ return true if date_or_time.nil?
104
+
105
+ date_or_time.to_time < @now_getter.now
106
+ end
107
+
108
+ # @param date_or_time [Date,Time,nil]
109
+ # @param period_name [Symbol]
110
+ # @param args [Object]
111
+ def compound_in_period?(date_or_time, period_name, *args)
112
+ # @sg-ignore
113
+ return less_than_n_days_ago?(date_or_time, *args) if period_name == :less_than_n_days_ago
114
+
115
+ if period_name == :greater_than_or_equal_to_n_days_from_today
116
+ return greater_than_or_equal_to_n_days_from_today?(date_or_time,
117
+ *args)
118
+ end
119
+ raise "Teach me how to handle period [#{period_name.inspect}, #{args.join(', ')}]"
120
+ end
121
+
96
122
  # bundle exec ./time.rb
97
123
  # :nocov:
98
124
  class << self
@@ -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.107.0'
6
+ VERSION = '0.109.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.107.0
4
+ version: 0.109.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vince Broz