Class: DecisionAgent::Simulation::ScenarioEngine::ProgressTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/decision_agent/simulation/scenario_engine.rb

Overview

Helper class for tracking progress

Instance Method Summary collapse

Constructor Details

#initialize(total, callback) ⇒ ProgressTracker



95
96
97
98
99
# File 'lib/decision_agent/simulation/scenario_engine.rb', line 95

def initialize(total, callback)
  @total = total
  @callback = callback
  @completed = 0
end

Instance Method Details

#incrementObject



101
102
103
104
105
106
107
108
109
110
# File 'lib/decision_agent/simulation/scenario_engine.rb', line 101

def increment
  @completed += 1
  return unless @callback

  @callback.call(
    completed: @completed,
    total: @total,
    percentage: (@completed.to_f / @total * 100).round(2)
  )
end