Sha256: 7fbd52388cc311ffbcbf14109a3737d8cff876eaedb37bdc22958975ea35402f

Contents?: true

Size: 1020 Bytes

Versions: 69

Compression:

Stored size: 1020 Bytes

Contents

require 'ruby-progressbar/time'

class   ProgressBar
class   Timer
  attr_accessor :started_at,
                :stopped_at

  def initialize(options = {})
    self.time = options[:time] || 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

69 entries across 61 versions & 13 rubygems

Version Path
kinetic_sdk-5.0.2.beta.2 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb
kinetic_sdk-5.0.2.beta.1 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb
kinetic_sdk-5.0.1 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb
kinetic_sdk-5.0.0 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb
kinetic_sdk-1.0.2 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb
kinetic_sdk-1.0.1 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb
kinetic_sdk-1.0.0 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb
kinetic_sdk-0.1.1 gems/ruby-progressbar-1.9.0/lib/ruby-progressbar/timer.rb
cspeezy_palindrome-0.3.0 path/ruby/2.6.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
cspeezy_palindrome-0.2.0 path/ruby/2.6.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
cspeezy_palindrome-0.1.0 path/ruby/2.6.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
steenfest_palindrome-0.1.2 ruby/2.5/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
steenfest_palindrome-0.1.1b ruby/2.5/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
nullifyable-0.1.0 vendor/bundle/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
dmurphy_palindrome-0.1.0 vendor/cache/ruby/2.3.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
dmurphy_palindrome-0.1.0 vendor/cache/ruby/2.3.0/gems/dmurphy_palindrome-0.1.0/vendor/cache/ruby/2.3.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/ruby-progressbar-1.10.0/lib/ruby-progressbar/timer.rb