Class: Hedra::ProgressTracker
- Inherits:
-
Object
- Object
- Hedra::ProgressTracker
- Defined in:
- lib/hedra/progress_tracker.rb
Overview
Track and display progress for batch operations
Instance Method Summary collapse
- #finish ⇒ Object
- #increment ⇒ Object
-
#initialize(total, quiet: false) ⇒ ProgressTracker
constructor
A new instance of ProgressTracker.
Constructor Details
#initialize(total, quiet: false) ⇒ ProgressTracker
Returns a new instance of ProgressTracker.
6 7 8 9 10 11 12 |
# File 'lib/hedra/progress_tracker.rb', line 6 def initialize(total, quiet: false) @total = total @current = 0 @quiet = quiet @start_time = Time.now @mutex = Mutex.new end |
Instance Method Details
#finish ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/hedra/progress_tracker.rb', line 21 def finish return if @quiet puts "\n" elapsed = Time.now - @start_time puts "Completed #{@total} items in #{elapsed.round(2)}s" end |
#increment ⇒ Object
14 15 16 17 18 19 |
# File 'lib/hedra/progress_tracker.rb', line 14 def increment @mutex.synchronize do @current += 1 update_display unless @quiet end end |