Class: MaintenanceTasks::Progress

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TextHelper, ActiveSupport::NumberHelper
Defined in:
app/models/maintenance_tasks/progress.rb

Overview

This class generates progress information about a Run.

Instance Method Summary collapse

Constructor Details

#initialize(run) ⇒ Progress

Sets the Progress initial state with a Run.

Parameters:

  • run (Run)

    the source of progress information.



12
13
14
# File 'app/models/maintenance_tasks/progress.rb', line 12

def initialize(run)
  @run = run
end

Instance Method Details

#maxInteger

The maximum amount of work expected to be done. This is extracted from the Run’s tick total attribute when present, or it is equal to the Run’s tick count.

This amount is enqual to the Run’s tick count if the tick count is greater than the tick total. This represents that the total was underestimated.

Returns:

  • (Integer)

    the progress maximum amount.



41
42
43
# File 'app/models/maintenance_tasks/progress.rb', line 41

def max
  estimatable? ? @run.tick_total : @run.tick_count
end

#textString

The text containing progress information. This describes the progress of the Run so far. It includes the percentage done out of the maximum, if an estimate is possible.

Returns:

  • (String)

    the text for the Run progress.



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/models/maintenance_tasks/progress.rb', line 50

def text
  count = @run.tick_count
  total = @run.tick_total

  if !total?
    "Processed #{number_to_delimited(count)} " \
      "#{"item".pluralize(count)}."
  elsif over_total?
    "Processed #{number_to_delimited(count)} " \
      "#{"item".pluralize(count)} " \
      "(expected #{number_to_delimited(total)})."
  else
    percentage = 100.0 * count / total

    "Processed #{number_to_delimited(count)} out of " \
      "#{number_to_delimited(total)} #{"item".pluralize(total)} " \
      "(#{number_to_percentage(percentage, precision: 0)})."
  end
end

#valueInteger?

Defines the value of progress information. This represents the amount that is already done out of the progress maximum.

For indefinite-style progress information, value is nil. That highlights that a Run is in progress but it is not possible to estimate how close to completion it is.

When a Run is stopped, the value is present even if there is no total. That represents a progress information that assumes that the current value is also equal to is max, showing a progress as completed.

Returns:

  • (Integer)

    if progress can be determined or the Run is stopped.

  • (nil)

    if progress can’t be determined and the Run isn’t stopped.



29
30
31
# File 'app/models/maintenance_tasks/progress.rb', line 29

def value
  @run.tick_count if estimatable? || @run.stopped?
end