Class: Formatador::ProgressBar
- Inherits:
-
Object
- Object
- Formatador::ProgressBar
- Defined in:
- lib/formatador/progressbar.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
Returns the value of attribute current.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#total ⇒ Object
Returns the value of attribute total.
Instance Method Summary collapse
- #increment(increment = 1) ⇒ Object
-
#initialize(total, opts = {}, &block) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
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
#current ⇒ Object
Returns the value of attribute current.
7 8 9 |
# File 'lib/formatador/progressbar.rb', line 7 def current @current end |
#opts ⇒ Object
Returns the value of attribute opts.
7 8 9 |
# File 'lib/formatador/progressbar.rb', line 7 def opts @opts end |
#total ⇒ Object
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.(current, total, opts) end end |