Sha256: 44ebe5e9a1d75e6919b3d5122738ebe045b7bee73e76a187079dcc5e37fa297b

Contents?: true

Size: 1.17 KB

Versions: 4001

Compression:

Stored size: 1.17 KB

Contents

class   ProgressBar
module  Projectors
class   SmoothedAverage
  DEFAULT_STRENGTH           = 0.1
  DEFAULT_BEGINNING_POSITION = 0

  attr_accessor :samples,
                :strength
  attr_reader   :projection

  def initialize(options = {})
    self.samples    = []
    self.projection = 0.0
    self.strength   = options[:strength] || DEFAULT_STRENGTH

    start(:at => DEFAULT_BEGINNING_POSITION)
  end

  def start(options = {})
    self.projection = 0.0
    self.progress   = samples[0] = (options[:at] || progress)
  end

  def decrement
    self.progress -= 1
  end

  def increment
    self.progress += 1
  end

  def progress
    samples[1]
  end

  def total=(_new_total); end

  def reset
    start(:at => samples[0])
  end

  def progress=(new_progress)
    samples[1] = new_progress
    self.projection = \
      self.class.calculate(
        @projection,
        absolute,
        strength
      )
  end

  def none?
    projection.zero?
  end

  def self.calculate(current_projection, new_value, rate)
    (new_value * (1.0 - rate)) + (current_projection * rate)
  end

  protected

  attr_writer :projection

  private

  def absolute
    samples[1] - samples[0]
  end
end
end
end

Version data entries

4,001 entries across 4,001 versions & 27 rubygems

Version Path
cybrid_api_bank_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_organization_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_id_ruby-0.123.12 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_bank_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_organization_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_id_ruby-0.123.11 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_id_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_bank_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_organization_ruby-0.123.10 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_organization_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_id_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_bank_ruby-0.123.7 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
ory-client-1.15.12 vendor/bundle/ruby/3.1.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_bank_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_id_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_organization_ruby-0.123.4 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_bank_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_organization_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_id_ruby-0.123.3 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb
cybrid_api_id_ruby-0.123.2 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/projectors/smoothed_average.rb