Sha256: 6fb7469f4e07b923997fc5a5151f0b2854335195f458f46f65fd5c1a1ce68bb6

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require 'tty/progressbar'
require 'colorize'

module Chronicle
  module ETL
    module Utils

      class ProgressBar
        FORMAT_WITH_TOTAL = [
          ':bar ',
          ':percent'.light_white,
          ' | '.light_black,
          ':current'.light_white,
          '/'.light_black,
          ':total'.light_white,
          ' ('.light_black,
          'ELAPSED:'.light_black,
          ':elapsed'.light_white,
          ' | ETA:'.light_black,
          ':eta'.light_white,
          ' | RATE: '.light_black,
          ':mean_rate'.light_white,
          '/s) '.light_black
        ].join.freeze

        FORMAT_WITHOUT_TOTAL = [
          ':current'.light_white,
          '/'.light_black,
          '???'.light_white,
          ' ('.light_black,
          'ELAPSED:'.light_black,
          ':elapsed'.light_white,
          ' | ETA:'.light_black,
          '??:??'.light_white,
          ' | RATE: '.light_black,
          ':mean_rate'.light_white,
          '/s) '.light_black
        ].join.freeze

        def initialize(title: 'Loading', total:)
          opts = {
            clear: true,
            complete: '▓'.light_blue,
            incomplete: '░'.blue,
            frequency: 10
          }

          if total
            opts[:total] = total
            format_str = "#{title} #{FORMAT_WITH_TOTAL}"
            @pbar = TTY::ProgressBar.new(FORMAT_WITH_TOTAL, opts)
          else
            format_str = "#{title} #{FORMAT_WITHOUT_TOTAL}"
            opts[:no_width] = true
          end

          @pbar = TTY::ProgressBar.new(format_str, opts)

          @pbar.resize
        end

        def increment
          @pbar.advance(1)
        end

        def log(message)
          @pbar.log message
        end

        def finish
          @pbar.finish
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
chronicle-etl-0.2.4 lib/chronicle/etl/utils/progress_bar.rb