checkoff 0.50.0 → 0.52.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: 8bdb0bf4cc27747e4ce2255f22438fe749beedff628a70ebe1b24252ed7c0bb3
4
- data.tar.gz: ddf33a293e522f25f1ee10df10fbd9b80fdcca9ea29d32fa1f3d21e3d8bf4ead
3
+ metadata.gz: c150952f6929705defdcfb0d506308ca1d5e285e732eb6715fcb9c03a78e8ad4
4
+ data.tar.gz: ac88caf643edccda95c7fcf345e601bcee87f6f1e59b0af83136fe7194420766
5
5
  SHA512:
6
- metadata.gz: b69f0673147f4581d3cb983e77639ef811a3b9895b89a8c11c07951b02362142ee412c799cd81333727b191e9cae0e7df800ce805f4dfcd354d6d897d78ac202
7
- data.tar.gz: c788eb613e2ae5ae0a28d433944f982b55fe246c9b1ae9283220147eb4d2d8c0904a65a7a2f26c2abff8bae351ebdb42e2b5963d9d8b42ff806e85d66a5a5248
6
+ metadata.gz: 3d4a6454075c4e2332b3c59ca3f93b3358b77f77f8bf43e2c7e28f9a615d73b204edc3b1ac00b51acbe109355ae3b6a16b30944bd13ea6be653dc28e2e45d857
7
+ data.tar.gz: 774fb7f8311cc540f762f36d30f79b59de16897105ae8a34496585a5c1c6e19353b37736b691b98b3bc447a88685bdd73db297dbaa23f2bde1b3d70f0ef47ab2
data/Gemfile.lock CHANGED
@@ -12,7 +12,7 @@ GIT
12
12
  PATH
13
13
  remote: .
14
14
  specs:
15
- checkoff (0.50.0)
15
+ checkoff (0.52.0)
16
16
  activesupport
17
17
  asana (> 0.10.0)
18
18
  cache_method
@@ -4,9 +4,21 @@
4
4
  # @!parse
5
5
  # class Time
6
6
  # class << self
7
- # # @param date [String]
7
+ # # @param time [String]
8
8
  # # @return [Time]
9
+ # def parse(time); end
10
+ # end
11
+ # # https://ruby-doc.org/3.2.2/exts/date/Time.html#method-i-to_date#
12
+ # # @return [Date]
13
+ # def to_date; end
14
+ # end
15
+ # class Date
16
+ # class << self
17
+ # # @param date [String]
18
+ # # @return [Date]
9
19
  # def parse(date); end
20
+ # # @return [Date]
21
+ # def today; end
10
22
  # end
11
23
  # end
12
24
  # module Asana
@@ -26,6 +38,10 @@
26
38
  # module Resources
27
39
  # # https://developers.asana.com/reference/gettask
28
40
  # class Task
41
+ # # @return [String,nil]
42
+ # def due_at; end
43
+ # # @return [String,nil]
44
+ # def due_on; end
29
45
  # # @return [Hash<String, String>, nil]
30
46
  # def assignee; end
31
47
  # # @return [String, nil]
@@ -14,6 +14,45 @@ module Checkoff
14
14
  end
15
15
 
16
16
  # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)] See https://developers.asana.com/docs/search-tasks-in-a-workspace
17
+ def handle_through_next
18
+ due_date_value = get_single_param('due_date.value').to_i
19
+
20
+ validate_unit_is_day!
21
+
22
+ # @sg-ignore
23
+ # @type [Date]
24
+ before = Date.today + due_date_value
25
+ # 'due_on.before' => '2023-01-01',
26
+ # 'due_on.after' => '2023-01-01',
27
+ # [{ 'due_on.before' => '2023-09-01' }, []]
28
+ [{ 'due_on.before' => before.to_s }, []]
29
+ end
30
+
31
+ # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)] See https://developers.asana.com/docs/search-tasks-in-a-workspace
32
+ def handle_between
33
+ due_date_after = get_single_param('due_date.after')
34
+ raise 'Teach me how to handle due_date_before' if date_url_params.key? 'due_date.before'
35
+
36
+ validate_unit_not_provided!
37
+
38
+ # Example value: 1702857600000
39
+ after = Time.at(due_date_after.to_i / 1000).to_date
40
+ [{ 'due_on.after' => after.to_s }, []]
41
+ end
42
+
43
+ # @param param_key [String]
44
+ # @return [String]
45
+ def get_single_param(param_key)
46
+ raise "Expected #{param_key} to have at least one value" unless date_url_params.key? param_key
47
+
48
+ value = date_url_params.fetch(param_key)
49
+
50
+ raise "Expected #{param_key} to have one value" if value.length != 1
51
+
52
+ value[0]
53
+ end
54
+
55
+ # @return [Array(Hash<String, String>, Array<[Symbol, Array]>)]
17
56
  def convert
18
57
  return [{}, []] if date_url_params.empty?
19
58
 
@@ -21,38 +60,29 @@ module Checkoff
21
60
  # due_date.operator=through_next
22
61
  # due_date.value=0
23
62
  # due_date.unit=day
24
- validate_due_date_through_next!
63
+ due_date_operator = get_single_param('due_date.operator')
25
64
 
26
- value = date_url_params.fetch('due_date.value').fetch(0).to_i
65
+ return handle_through_next if due_date_operator == 'through_next'
27
66
 
28
- # @sg-ignore
29
- # @type [Date]
30
- before = Date.today + value
67
+ return handle_between if due_date_operator == 'between'
31
68
 
32
- validate_unit_is_day!
33
-
34
- # 'due_on.before' => '2023-01-01',
35
- # 'due_on.after' => '2023-01-01',
36
- # [{ 'due_on.before' => '2023-09-01' }, []]
37
- [{ 'due_on.before' => before.to_s }, []]
69
+ raise "Teach me how to handle date mode: #{due_date_operator.inspect}."
38
70
  end
39
71
 
40
72
  private
41
73
 
42
74
  # @return [void]
43
- def validate_unit_is_day!
44
- unit = date_url_params.fetch('due_date.unit').fetch(0)
75
+ def validate_unit_not_provided!
76
+ return unless date_url_params.key? 'due_date.unit'
45
77
 
46
- raise 'Teach me how to handle other time units' unless unit == 'day'
78
+ raise "Teach me how to handle other due_date.unit for these params: #{date_url_params.inspect}"
47
79
  end
48
80
 
49
81
  # @return [void]
50
- def validate_due_date_through_next!
51
- due_date_operators = date_url_params.fetch('due_date.operator')
52
-
53
- return if due_date_operators == ['through_next']
82
+ def validate_unit_is_day!
83
+ unit = date_url_params.fetch('due_date.unit').fetch(0)
54
84
 
55
- raise "Teach me how to handle date mode: #{due_date_operators}."
85
+ raise 'Teach me how to handle other time units' unless unit == 'day'
56
86
  end
57
87
 
58
88
  # @return [Hash<String, Array<String>>]
@@ -38,9 +38,21 @@ module Checkoff
38
38
  # @sg-ignore
39
39
  # @return [Date, nil]
40
40
  def pull_date_field_by_name_or_raise(task, field_name)
41
- raise "Teach me how to handle field #{field_name}" unless field_name == :modified_at
41
+ if field_name == :modified
42
+ return Time.parse(task.modified_at).to_date unless task.modified_at.nil?
42
43
 
43
- task.modified_at
44
+ return nil
45
+ end
46
+
47
+ if field_name == :due
48
+ return Time.parse(task.due_at).to_date unless task.due_at.nil?
49
+
50
+ return Date.parse(task.due_on) unless task.due_on.nil?
51
+
52
+ return nil
53
+ end
54
+
55
+ raise "Teach me how to handle field #{field_name}"
44
56
  end
45
57
 
46
58
  # @sg-ignore
@@ -372,13 +384,43 @@ module Checkoff
372
384
  #
373
385
  # @return [Boolean]
374
386
  def evaluate(task, field_name, num_days)
375
- time = pull_date_field_by_name_or_raise(task, field_name)
387
+ date = pull_date_field_by_name_or_raise(task, field_name)
376
388
 
377
- return false if time.nil?
389
+ return false if date.nil?
378
390
 
379
- n_days_ago = (Time.now - (num_days * 24 * 60 * 60))
380
391
  # @sg-ignore
381
- time < n_days_ago
392
+ n_days_ago = Date.today - num_days
393
+ # @sg-ignore
394
+ date < n_days_ago
395
+ end
396
+ end
397
+
398
+ # :field_greater_than_or_equal_to_n_days_from_today
399
+ class FieldGreaterThanOrEqualToNDaysFromTodayFunctionEvaluator < FunctionEvaluator
400
+ FUNCTION_NAME = :field_greater_than_or_equal_to_n_days_from_today
401
+
402
+ def matches?
403
+ fn?(task_selector, FUNCTION_NAME)
404
+ end
405
+
406
+ def evaluate_arg?(_index)
407
+ false
408
+ end
409
+
410
+ # @param task [Asana::Resources::Task]
411
+ # @param field_name [Symbol]
412
+ # @param num_days [Integer]
413
+ #
414
+ # @return [Boolean]
415
+ def evaluate(task, field_name, num_days)
416
+ date = pull_date_field_by_name_or_raise(task, field_name)
417
+
418
+ return false if date.nil?
419
+
420
+ # @sg-ignore
421
+ n_days_from_today = Date.today + num_days
422
+ # @sg-ignore
423
+ date >= n_days_from_today
382
424
  end
383
425
  end
384
426
 
@@ -481,6 +523,7 @@ module Checkoff
481
523
  Checkoff::TaskSelectorClasses::UnassignedPFunctionEvaluator,
482
524
  Checkoff::TaskSelectorClasses::DueDateSetPFunctionEvaluator,
483
525
  Checkoff::TaskSelectorClasses::FieldLessThanNDaysAgoFunctionEvaluator,
526
+ Checkoff::TaskSelectorClasses::FieldGreaterThanOrEqualToNDaysFromTodayFunctionEvaluator,
484
527
  Checkoff::TaskSelectorClasses::CustomFieldLessThanNDaysFromNowFunctionEvaluator,
485
528
  Checkoff::TaskSelectorClasses::CustomFieldGreaterThanOrEqualToNDaysFromNowFunctionEvaluator,
486
529
  Checkoff::TaskSelectorClasses::StringLiteralEvaluator,
@@ -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.50.0'
6
+ VERSION = '0.52.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.50.0
4
+ version: 0.52.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-09-03 00:00:00.000000000 Z
11
+ date: 2023-09-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport