class DynportTools::ETA
Constants
- FACTORS
Attributes
current[RW]
started[RW]
total[RW]
Public Class Methods
from_time_string(string, options = {})
click to toggle source
# File lib/dynport_tools/eta.rb, line 66 def from_time_string(string, options = {}) self.new(options.merge(:started => Time.now - parse_time_string(string))) end
new(options = {})
click to toggle source
# File lib/dynport_tools/eta.rb, line 4 def initialize(options = {}) options.each do |key, value| self.send(:"#{key}=", value) if self.respond_to?(:"#{key}=") end end
parse_time_string(string)
click to toggle source
# File lib/dynport_tools/eta.rb, line 58 def parse_time_string(string) sum = 0.0 string.split(":").map { |s| s.to_i }.reverse.each_with_index do |value, i| sum += value * FACTORS[i] end sum end
Public Instance Methods
eta()
click to toggle source
# File lib/dynport_tools/eta.rb, line 32 def eta Time.now + to_go end
pending()
click to toggle source
# File lib/dynport_tools/eta.rb, line 15 def pending raise_error_when_current_or_total_not_set total - current end
per_second()
click to toggle source
# File lib/dynport_tools/eta.rb, line 36 def per_second current / running_for end
percs()
click to toggle source
# File lib/dynport_tools/eta.rb, line 10 def percs raise_error_when_current_or_total_not_set current.to_f / total end
raise_error_when_current_or_total_not_set()
click to toggle source
# File lib/dynport_tools/eta.rb, line 51 def raise_error_when_current_or_total_not_set raise "current and total must be set" if total.nil? || current.nil? end
running_for()
click to toggle source
# File lib/dynport_tools/eta.rb, line 20 def running_for Time.now - started end
seconds_to_time(time)
click to toggle source
# File lib/dynport_tools/eta.rb, line 40 def seconds_to_time(time) hours = time / 3600.0 minutes = time / 60.0 seconds = time "%02d:%02d:%02d" % [hours.floor, (minutes.floor % 3600) % 60, seconds.floor % 60] end
to_go()
click to toggle source
# File lib/dynport_tools/eta.rb, line 28 def to_go total_time - running_for end
to_s()
click to toggle source
# File lib/dynport_tools/eta.rb, line 47 def to_s "%.2f%%, %.2f/second, ETA: %s" % [percs * 100, per_second, eta.iso8601] end
total_time()
click to toggle source
# File lib/dynport_tools/eta.rb, line 24 def total_time running_for / percs end