Module: Omnizip::Progress

Defined in:
lib/omnizip/progress.rb,
lib/omnizip/progress/log_reporter.rb,
lib/omnizip/progress/progress_bar.rb,
lib/omnizip/progress/silent_reporter.rb,
lib/omnizip/progress/console_reporter.rb,
lib/omnizip/progress/progress_tracker.rb,
lib/omnizip/progress/callback_reporter.rb,
lib/omnizip/progress/progress_reporter.rb,
lib/omnizip/progress/operation_progress.rb

Overview

Progress tracking module.

This module provides real-time progress tracking for long-running operations with multiple reporting strategies (console, callback, log file, etc.) and integrated ETA calculation.

Examples:

Basic progress tracking

tracker = Omnizip::Progress.track(total_files: 100, total_bytes: 1.gigabyte)
# Update progress as work is done
tracker.update(files: 10, bytes: 100.megabytes, current_file: "file.txt")
puts tracker.percentage # => 10.0
puts tracker.eta_formatted # => "2m 30s"

With console progress bar

tracker = Omnizip::Progress.track(
  total_files: 100,
  total_bytes: 1.gigabyte,
  reporter: :console
)

With custom callback

tracker = Omnizip::Progress.track(
  total_files: 100,
  total_bytes: 1.gigabyte
) do |progress|
  puts "#{progress.percentage}% complete"
end

Defined Under Namespace

Classes: CallbackReporter, Configuration, ConsoleReporter, LogReporter, OperationProgress, ProgressBar, ProgressReporter, ProgressTracker, SilentReporter

Class Method Summary collapse

Class Method Details

.build_reporters(reporter, block) ⇒ Array<ProgressReporter>

Build reporters from various input formats

Parameters:

  • reporter (Symbol, ProgressReporter, Array)

    Reporter specification

  • block (Proc)

    Optional callback block

Returns:



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/omnizip/progress.rb', line 91

def self.build_reporters(reporter, block)
  reporters = []

  # Handle callback block
  reporters << CallbackReporter.new(&block) if block

  # Handle reporter parameter
  case reporter
  when :auto
    reporters << ConsoleReporter.new if $stdout.tty?
  when :console
    reporters << ConsoleReporter.new
  when :silent
    reporters << SilentReporter.new
  when Array
    reporters.concat(reporter)
  when ProgressReporter
    reporters << reporter
  when Symbol
    raise ArgumentError, "Unknown reporter type: #{reporter}"
  end

  # Default to silent if no reporters
  reporters << SilentReporter.new if reporters.empty?

  reporters
end

.configurationConfiguration

Get global configuration

Returns:



82
83
84
# File 'lib/omnizip/progress.rb', line 82

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|config| ... } ⇒ Object

Configure global progress settings

Yields:

  • (config)

    Configuration block



75
76
77
# File 'lib/omnizip/progress.rb', line 75

def self.configure
  yield configuration
end

.track(total_files:, total_bytes:, reporter: :auto, update_interval: 0.5, eta_strategy: :exponential_smoothing) {|progress| ... } ⇒ ProgressTracker

Track an operation's progress

Parameters:

  • total_files (Integer)

    Total number of files to process

  • total_bytes (Integer)

    Total bytes to process

  • reporter (Symbol, ProgressReporter, Array) (defaults to: :auto)

    Reporter(s) to use

  • update_interval (Float) (defaults to: 0.5)

    Minimum seconds between reports

  • eta_strategy (Symbol) (defaults to: :exponential_smoothing)

    ETA estimation strategy

Yields:

  • (progress)

    Optional callback block for custom reporting

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/omnizip/progress.rb', line 58

def self.track(total_files:, total_bytes:, reporter: :auto,
               update_interval: 0.5, eta_strategy: :exponential_smoothing,
               &block)
  reporters = build_reporters(reporter, block)

  ProgressTracker.new(
    total_files: total_files,
    total_bytes: total_bytes,
    reporters: reporters,
    update_interval: update_interval,
    eta_strategy: eta_strategy,
  )
end