Sha256: a158608cc524ccbb4cfddb8c7512682cd321a82f206a8705a7314a68a0a24a89

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 Bytes

Contents

require 'ruby-progressbar'
require 'colorize'

module Chronicle
  module Etl
    module Utils
      class ProgressBarWrapper
        def initialize(count)
          return unless tty?

          @pbar = ProgressBar.create(
            format: '%b%i  %c/%C (%P%%)  %a %e  Rate: %R',
            remainder_mark: '░',
            progress_mark: '▓'.colorize(:light_green),
            starting_time: 0,
            lenth: 200,
            throttle_rate: 0.1,
            total: count,
            unknown_progress_animation_steps: ['▓░░░', '░▓░░', '░░▓░', '░░░▓']
          )
        end

        def increment
          @pbar&.increment
        end

        def log(message)
          @pbar&.log message
        end

        def finish
          @pbar&.finish
        end

        private

        def tty?
          $stdout.isatty
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
chronicle-etl-0.1.2 lib/chronicle/etl/utils/progress_bar_wrapper.rb
chronicle-etl-0.1.1 lib/chronicle/etl/utils/progress_bar_wrapper.rb
chronicle-etl-0.1.0 lib/chronicle/etl/utils/progress_bar_wrapper.rb