Class: Formatador::ProgressBar

Inherits:
Object
  • Object
show all
Defined in:
lib/formatador/progressbar.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total, opts = {}, &block) ⇒ ProgressBar

Returns a new instance of ProgressBar.



9
10
11
12
13
14
15
# 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

Instance Attribute Details

#currentObject

Returns the value of attribute current.



7
8
9
# File 'lib/formatador/progressbar.rb', line 7

def current
  @current
end

#optsObject

Returns the value of attribute opts.



7
8
9
# File 'lib/formatador/progressbar.rb', line 7

def opts
  @opts
end

#totalObject

Returns the value of attribute total.



7
8
9
# File 'lib/formatador/progressbar.rb', line 7

def total
  @total
end

Instance Method Details

#increment(increment = 1) ⇒ Object



17
18
19
20
21
22
23
24
# 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