Sha256: af785b24464ce2e6a8ce63b982bafa480d6cfe5a7771373d646fd2480a206f20

Contents?: true

Size: 711 Bytes

Versions: 4341

Compression:

Stored size: 711 Bytes

Contents

class   ProgressBar
module  Components
class   Rate
  attr_accessor :rate_scale,
                :timer,
                :progress

  def initialize(options = {})
    self.rate_scale = options[:rate_scale] || lambda { |x| x }
    self.timer      = options[:timer]
    self.progress   = options[:progress]
  end

  def rate_of_change(format_string = '%i')
    return '0' if elapsed_seconds <= 0

    format_string % scaled_rate
  end

  def rate_of_change_with_precision
    rate_of_change('%.2f')
  end

  private

  def scaled_rate
    rate_scale.call(base_rate)
  end

  def base_rate
    progress.absolute / elapsed_seconds
  end

  def elapsed_seconds
    timer.elapsed_whole_seconds.to_f
  end
end
end
end

Version data entries

4,341 entries across 4,341 versions & 29 rubygems

Version Path
cybrid_api_id_ruby-0.123.179 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.179 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.177 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_id_ruby-0.123.177 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.176 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_id_ruby-0.123.176 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.175 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_id_ruby-0.123.175 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_id_ruby-0.123.174 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.174 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_id_ruby-0.123.173 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.173 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
ory-client-1.16.3 vendor/bundle/ruby/3.1.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.172 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_id_ruby-0.123.172 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_id_ruby-0.123.171 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.171 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_id_ruby-0.123.170 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.170 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb
cybrid_api_organization_ruby-0.123.163 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.13.0/lib/ruby-progressbar/components/rate.rb