Sha256: ae75e8c8fbbe46933d1e48f27be86d326207669e1bd3eb0478c1e3e613e55c83

Contents?: true

Size: 1.01 KB

Versions: 2663

Compression:

Stored size: 1.01 KB

Contents

require 'ruby-progressbar/time'

class   ProgressBar
class   Timer
  attr_accessor :started_at,
                :stopped_at

  def initialize(options = {})
    self.time = options[:time] || ::ProgressBar::Time.new
  end

  def start
    self.started_at = stopped? ? time.now - (stopped_at - started_at) : time.now
    self.stopped_at = nil
  end

  def stop
    return unless started?

    self.stopped_at = time.now
  end

  def pause
    stop
  end

  def resume
    start
  end

  def started?
    started_at
  end

  def stopped?
    stopped_at
  end

  def reset
    self.started_at = nil
    self.stopped_at = nil
  end

  def reset?
    !started_at
  end

  def restart
    reset
    start
  end

  def elapsed_seconds
    ((stopped_at || time.now) - started_at)
  end

  def elapsed_whole_seconds
    elapsed_seconds.floor
  end

  def divide_seconds(seconds)
    hours, seconds   = seconds.divmod(3600)
    minutes, seconds = seconds.divmod(60)

    [hours, minutes, seconds]
  end

  protected

  attr_accessor :time
end
end

Version data entries

2,663 entries across 2,621 versions & 34 rubygems

Version Path
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
avalara_sdk-24.12.0 vendor/bundle/ruby/2.7.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.20.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.19.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.18.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.17.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.15.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.14.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.13.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.12.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.11.1 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
mux_ruby-3.11.0 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb
cybrid_api_organization_ruby-0.62.65 vendor/bundle/ruby/3.2.0/gems/ruby-progressbar-1.11.0/lib/ruby-progressbar/timer.rb