class Formatador::ProgressBar

Attributes

current[RW]
opts[RW]
total[RW]

Public Class Methods

new(total, opts = {}, &block) click to toggle source
# File lib/formatador/progressbar.rb, line 9
def initialize(total, opts = {}, &block)
  @current = opts.delete(:start) || 0
  @total   = total.to_i
  @opts    = opts
  @lock    = Mutex.new
  @complete_proc = block_given? ? block : Proc.new { }
end

Public Instance Methods

increment(increment = 1) click to toggle source
# File lib/formatador/progressbar.rb, line 17
def increment(increment = 1)
  @lock.synchronize do
    return if complete?
    @current += increment.to_i
    @complete_proc.call(self) if complete?
    Formatador.redisplay_progressbar(current, total, opts)
  end
end

Private Instance Methods

complete?() click to toggle source
# File lib/formatador/progressbar.rb, line 28
def complete?
  current == total
end