class TaskProgressBar

Constants

VERSION

Public Class Methods

new(total) click to toggle source
# File lib/task_progress_bar.rb, line 4
def initialize(total)
  @total      = total || 1
  @total_bar  = ( total < 50 ? total : 50 )
  @start_time = Time.now
  @i          = 0
end

Public Instance Methods

bar() click to toggle source
# File lib/task_progress_bar.rb, line 16
def bar
  "\r[%d/%d][%s][%d%%][%s][%s]" % [@i, @total, green_elapsed_bar, elapsed_percent, elapsed_time_formated, time_left]
end
bar_quantity() click to toggle source
# File lib/task_progress_bar.rb, line 32
def bar_quantity
  ((@i*1.00/total_progress).to_i)
end
count(value = 1) click to toggle source
# File lib/task_progress_bar.rb, line 20
def count(value = 1)
  @i += value
end
elapsed_bar() click to toggle source
# File lib/task_progress_bar.rb, line 40
def elapsed_bar
  "%-#{@total_bar}s" % [symbol * bar_quantity]
end
elapsed_percent() click to toggle source
# File lib/task_progress_bar.rb, line 44
def elapsed_percent
  ((@i*1.00/@total)*100).to_i
end
elapsed_time() click to toggle source
# File lib/task_progress_bar.rb, line 48
def elapsed_time
  Time.now - @start_time
end
elapsed_time_formated() click to toggle source
# File lib/task_progress_bar.rb, line 52
def elapsed_time_formated
  time_formated( elapsed_time )
end
green_elapsed_bar() click to toggle source
# File lib/task_progress_bar.rb, line 36
def green_elapsed_bar
  "\033[32m#{ elapsed_bar }\033[0m"
end
step() click to toggle source
# File lib/task_progress_bar.rb, line 11
def step
  self.count
  STDOUT.print self.bar
end
symbol() click to toggle source
# File lib/task_progress_bar.rb, line 24
def symbol
  '#'
end
time_formated( value ) click to toggle source
# File lib/task_progress_bar.rb, line 65
def time_formated( value )
  Time.at( value ).utc.strftime("%H:%M:%S")
end
time_left() click to toggle source
# File lib/task_progress_bar.rb, line 61
def time_left
  time_formated( time_left_in_seconds )
end
time_left_in_seconds() click to toggle source
# File lib/task_progress_bar.rb, line 56
def time_left_in_seconds
  return 0 if @i == 0
  ( (elapsed_time / @i) * (@total.to_f - @i) ).to_i
end
total_progress() click to toggle source
# File lib/task_progress_bar.rb, line 28
def total_progress
  @total / @total_bar
end