Class: Factorix::Progress::PresenterAdapter
- Inherits:
-
Object
- Object
- Factorix::Progress::PresenterAdapter
- Defined in:
- lib/factorix/progress/presenter_adapter.rb
Overview
Adapter to make TTY::ProgressBar compatible with Presenter interface
This adapter wraps a TTY::ProgressBar instance and provides the same interface as Progress::Presenter, allowing them to be used interchangeably.
Instance Method Summary collapse
-
#finish ⇒ void
Mark the progress as finished.
-
#initialize(tty_bar, mutex) ⇒ PresenterAdapter
constructor
Create a new presenter adapter.
-
#start(total:, format: nil) ⇒ void
Start the progress presentation.
-
#update(current) ⇒ void
Update the progress to a specific value.
Constructor Details
#initialize(tty_bar, mutex) ⇒ PresenterAdapter
Create a new presenter adapter
14 15 16 17 18 |
# File 'lib/factorix/progress/presenter_adapter.rb', line 14 def initialize(, mutex) @tty_bar = @mutex = mutex @started = false end |
Instance Method Details
#finish ⇒ void
This method returns an undefined value.
Mark the progress as finished
43 |
# File 'lib/factorix/progress/presenter_adapter.rb', line 43 def finish = @mutex.synchronize { @tty_bar.finish } |
#start(total:, format: nil) ⇒ void
This method returns an undefined value.
Start the progress presentation
25 26 27 28 29 30 31 32 |
# File 'lib/factorix/progress/presenter_adapter.rb', line 25 def start(total:, format: nil) _ = format # Acknowledge unused parameter @mutex.synchronize do @tty_bar.update(total:) if total @tty_bar.start unless @started @started = true end end |
#update(current) ⇒ void
This method returns an undefined value.
Update the progress to a specific value
38 |
# File 'lib/factorix/progress/presenter_adapter.rb', line 38 def update(current) = @mutex.synchronize { @tty_bar.current = current } |