lib/checkoff/internal/task_selector_evaluator.rb in checkoff-0.46.1 vs lib/checkoff/internal/task_selector_evaluator.rb in checkoff-0.47.0

- old
+ new

@@ -30,11 +30,22 @@ # @param fn_name [Symbol] def fn?(object, fn_name) object.is_a?(Array) && !object.empty? && [fn_name, fn_name.to_s].include?(object[0]) end + # @param task [Asana::Resources::Task] + # @param field_name [Symbol] + # # @sg-ignore + # @return [Date, nil] + def pull_date_field_by_name_or_raise(task, field_name) + raise "Teach me how to handle field #{field_name}" unless field_name == :modified_at + + task.modified_at + end + + # @sg-ignore # @param task [Asana::Resources::Task] # @param custom_field_gid [String] # @return [Hash] def pull_custom_field_or_raise(task, custom_field_gid) # @type [Array<Hash>] @@ -328,10 +339,38 @@ actual_custom_field_values_gids.include?(custom_field_value) end end end + # :field_less_than_n_days_ago + class FieldLessThanNDaysAgoFunctionEvaluator < FunctionEvaluator + FUNCTION_NAME = :field_less_than_n_days_ago + + def matches? + fn?(task_selector, FUNCTION_NAME) + end + + def evaluate_arg?(_index) + false + end + + # @param task [Asana::Resources::Task] + # @param field_name [Symbol] + # @param num_days [Integer] + # + # @return [Boolean] + def evaluate(task, field_name, num_days) + time = pull_date_field_by_name_or_raise(task, field_name) + + return false if time.nil? + + n_days_ago = (Time.now - (num_days * 24 * 60 * 60)) + # @sg-ignore + time < n_days_ago + end + end + # :custom_field_less_than_n_days_from_now function class CustomFieldLessThanNDaysFromNowFunctionEvaluator < FunctionEvaluator FUNCTION_NAME = :custom_field_less_than_n_days_from_now def matches? @@ -425,9 +464,10 @@ Checkoff::TaskSelectorClasses::CustomFieldGidValueContainsAnyGidFunctionEvaluator, Checkoff::TaskSelectorClasses::CustomFieldGidValueContainsAllGidsFunctionEvaluator, Checkoff::TaskSelectorClasses::AndFunctionEvaluator, Checkoff::TaskSelectorClasses::DuePFunctionEvaluator, Checkoff::TaskSelectorClasses::DueDateSetPFunctionEvaluator, + Checkoff::TaskSelectorClasses::FieldLessThanNDaysAgoFunctionEvaluator, Checkoff::TaskSelectorClasses::CustomFieldLessThanNDaysFromNowFunctionEvaluator, Checkoff::TaskSelectorClasses::CustomFieldGreaterThanOrEqualToNDaysFromNowFunctionEvaluator, Checkoff::TaskSelectorClasses::StringLiteralEvaluator, ].freeze