Class: Checkoff::SelectorClasses::Task::LastStoryCreatedLessThanNDaysAgoPFunctionEvaluator

Inherits:
FunctionEvaluator show all
Defined in:
lib/checkoff/internal/selector_classes/task.rb

Overview

:last_story_created_less_than_n_days_ago? function

Constant Summary collapse

FUNCTION_NAME =
:last_story_created_less_than_n_days_ago?

Instance Method Summary collapse

Methods inherited from FunctionEvaluator

#initialize

Constructor Details

This class inherits a constructor from Checkoff::SelectorClasses::Task::FunctionEvaluator

Instance Method Details

#evaluate(task, num_days, excluding_resource_subtypes) ⇒ Boolean

Parameters:

  • task (Asana::Resources::Task)
  • num_days (Integer)
  • excluding_resource_subtypes (Array<String>)

Returns:

  • (Boolean)


187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/checkoff/internal/selector_classes/task.rb', line 187

def evaluate(task, num_days, excluding_resource_subtypes)
  # for whatever reason, .last on the enumerable does not impose ordering; .to_a does!

  # @type [Array<Asana::Resources::Story>]
  stories = task.stories(per_page: 100).to_a.reject do |story|
    excluding_resource_subtypes.include? story.resource_subtype
  end
  return true if stories.empty? # no stories == infinitely old!

  last_story = stories.last
  last_story_created_at = Time.parse(last_story.created_at)
  n_days_ago = Time.now - (num_days * 24 * 60 * 60)
  last_story_created_at < n_days_ago
end

#evaluate_arg?(_index) ⇒ Boolean

Returns:

  • (Boolean)


179
180
181
# File 'lib/checkoff/internal/selector_classes/task.rb', line 179

def evaluate_arg?(_index)
  false
end

#matches?Boolean

Returns:

  • (Boolean)


175
176
177
# File 'lib/checkoff/internal/selector_classes/task.rb', line 175

def matches?
  fn?(selector, FUNCTION_NAME)
end