Sha256: b6f98b0ddbb691fd3d074e05c9518f98c8ed2ab09cd39047d608d05bc6bb0ecb
Contents?: true
Size: 1016 Bytes
Versions: 3
Compression:
Stored size: 1016 Bytes
Contents
require 'ruby-progressbar/time' class ProgressBar class Timer attr_accessor :started_at, :stopped_at def initialize(options = {}) self.time = options[:time] || Time 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
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
ruby-progressbar-1.7.5 | lib/ruby-progressbar/timer.rb |
ruby-progressbar-1.7.1 | lib/ruby-progressbar/timer.rb |
ruby-progressbar-1.7.0 | lib/ruby-progressbar/timer.rb |