class Echo::ProgressBar
Attributes
current[R]
start_time[R]
total[R]
Public Class Methods
new(total)
click to toggle source
# File lib/rake-echo.rb, line 8 def initialize(total) @total = total @current = 0 @start_time = Time.now @previous_time = @start_time end
Public Instance Methods
completed?()
click to toggle source
# File lib/rake-echo.rb, line 26 def completed? @current == @total end
increment(amount=1)
click to toggle source
# File lib/rake-echo.rb, line 15 def increment(amount=1) @current += amount display finish if completed? end
percentage()
click to toggle source
# File lib/rake-echo.rb, line 22 def percentage current.to_f / total.to_f end
Private Instance Methods
display()
click to toggle source
# File lib/rake-echo.rb, line 32 def display width = 20 current_col = (width * percentage).round current_perc = (percentage * 100.0).round(2) bar = "\r%+6.6s [%s%s] | %s" % [ current_perc.to_s + "%", "#" * current_col, "_" * (width - current_col), eta ] $stdout.print(bar) $stdout.flush end
eta()
click to toggle source
# File lib/rake-echo.rb, line 54 def eta time = if @current == 0 "--:--:--" else elapsed = Time.now - @start_time eta = (elapsed / @current) * (@total - @current); Time.at(eta).utc.strftime "%H:%M:%S" end "ETA: %s" % time end
finish()
click to toggle source
# File lib/rake-echo.rb, line 49 def finish $stdout.print("\n") $stdout.flush end