Class: Factorix::Progress::PresenterAdapter

Inherits:
Object
  • Object
show all
Defined in:
lib/factorix/progress/presenter_adapter.rb,
sig/factorix/progress/presenter_adapter.rbs

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

Constructor Details

#initialize(tty_bar, mutex) ⇒ PresenterAdapter

Create a new presenter adapter

Parameters:

  • tty_bar (TTY::ProgressBar) —

    the progress bar to adapt

  • mutex (Mutex) —

    mutex for thread-safe operations



14
15
16
17
18
# File 'lib/factorix/progress/presenter_adapter.rb', line 14

def initialize(tty_bar, mutex)
  @tty_bar = 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

Parameters:

  • total (Integer) —

    total size/count for progress tracking

  • format (String, nil) (defaults to: nil) —

    format string (ignored, already set in TTY::ProgressBar)

  • total: (Integer)
  • format: (String, nil) (defaults to: nil)


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

Parameters:

  • current (Integer) —

    current progress value



38
# File 'lib/factorix/progress/presenter_adapter.rb', line 38

def update(current) = @mutex.synchronize { @tty_bar.current = current }