Sha256: 4275718880e149af8b14ce66a8059b7792fd9cc8466f9415cc47c59ed5327628

Contents?: true

Size: 1.24 KB

Versions: 32

Compression:

Stored size: 1.24 KB

Contents

require 'rbbt/util/log'
require 'rbbt/util/log/progress/util'
require 'rbbt/util/log/progress/report'
module Log
  class ProgressBar

    attr_accessor :max, :ticks, :frequency, :depth, :desc
    def initialize(max = nil, options = {})
      options = Misc.add_defaults options, :depth => 0, :num_reports => 100, :desc => "Progress", :io => STDERR, :severity => Log.severity
      depth, num_reports, desc, io, severity = Misc.process_options options, :depth, :num_reports, :desc, :io, :severity

      @max = max
      @ticks = 0
      @frequency = 2
      @last_time = nil
      @last_count = nil
      @last_percent = nil
      @depth = depth
      @desc = desc
    end

    def percent
      (@ticks * 100) / @max
    end

    def tick(step = nil)
      return if ENV["RBBT_NO_PROGRESS"] == "true"
      @ticks += 1

      time = Time.now
      if @last_time.nil?
        @last_time = time
        @last_count = @ticks
        @start = time
        return
      end

      diff = time - @last_time
      report and return if diff > @frequency
      return unless max

      percent = self.percent
      if @last_percent.nil?
        @last_percent = percent
        return
      end
      report and return if percent > @last_percent and diff > 0.3
    end
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
rbbt-util-5.14.38 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.37 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.36 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.35 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.34 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.33 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.32 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.31 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.30 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.29 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.28 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.26 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.25 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.24 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.23 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.22 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.21 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.20 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.18 lib/rbbt/util/log/progress.rb
rbbt-util-5.14.17 lib/rbbt/util/log/progress.rb