Class: Checkoff::SelectorClasses::Task::EstimateExceedsDurationPFunctionEvaluator

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

Overview

:estimate_exceeds_duration?

Constant Summary collapse

FUNCTION_NAME =
:estimate_exceeds_duration?

Instance Method Summary collapse

Methods inherited from FunctionEvaluator

#initialize

Methods inherited from FunctionEvaluator

#evaluate_arg?

Constructor Details

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

Instance Method Details

#calculate_allocated_hours(task) ⇒ Float

Parameters:

  • task (Asana::Resources::Task)

Returns:

  • (Float)


213
214
215
216
217
218
219
220
221
222
# File 'lib/checkoff/internal/selector_classes/task.rb', line 213

def calculate_allocated_hours(task)
  due_on = nil
  start_on = nil
  start_on = Date.parse(task.start_on) unless task.start_on.nil?
  due_on = Date.parse(task.due_on) unless task.due_on.nil?
  allocated_hours = 8.0
  # @sg-ignore
  allocated_hours = (due_on - start_on + 1).to_i * 8.0 if start_on && due_on
  allocated_hours
end

#evaluate(task) ⇒ Boolean

Parameters:

  • task (Asana::Resources::Task)

Returns:

  • (Boolean)


226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'lib/checkoff/internal/selector_classes/task.rb', line 226

def evaluate(task)
  custom_field = @custom_fields.resource_custom_field_by_name(task, 'Estimated time')

  return false if custom_field.nil?

  # @sg-ignore
  # @type [Integer, nil]
  estimate_minutes = custom_field.fetch('number_value')

  # no estimate set
  return false if estimate_minutes.nil?

  estimate_hours = estimate_minutes / 60.0

  allocated_hours = calculate_allocated_hours(task)

  estimate_hours > allocated_hours
end

#matches?Boolean

Returns:

  • (Boolean)


207
208
209
# File 'lib/checkoff/internal/selector_classes/task.rb', line 207

def matches?
  fn?(selector, FUNCTION_NAME)
end