Class: Progress
Class Method Summary collapse
-
.io=(io) ⇒ Object
:nodoc:.
-
.start(name, total = 100) ⇒ Object
start progress indication ==== Examples Progress.start(‘Test’, 1000) …
- .step ⇒ Object
- .stop ⇒ Object
Instance Method Summary collapse
-
#initialize(name, total, level) ⇒ Progress
constructor
:nodoc:.
-
#message ⇒ Object
:nodoc:.
-
#start ⇒ Object
:nodoc:.
-
#step ⇒ Object
:nodoc:.
-
#stop ⇒ Object
:nodoc:.
Constructor Details
#initialize(name, total, level) ⇒ Progress
:nodoc:
48 49 50 51 52 53 54 |
# File 'lib/progress.rb', line 48 def initialize(name, total, level) @name = name + ': %s' @total = total @level = level @current = 0 start end |
Class Method Details
.io=(io) ⇒ Object
:nodoc:
43 44 45 |
# File 'lib/progress.rb', line 43 def self.io=(io) @io = io end |
.start(name, total = 100) ⇒ Object
start progress indication
Examples
Progress.start('Test', 1000)
...
Progress.step
...
Progress.stop('Test', 1000)
Progress.start('Test', 1000) do
...
Progress.step
...
end
19 20 21 22 23 24 25 26 |
# File 'lib/progress.rb', line 19 def self.start(name, total = 100) levels << new(name, total, levels.length) if block_given? yield stop end end |
.step ⇒ Object
28 29 30 31 |
# File 'lib/progress.rb', line 28 def self.step levels[-1].step end |
.stop ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/progress.rb', line 33 def self.stop levels.pop.stop unless levels.empty? else puts end end |
Instance Method Details
#message ⇒ Object
:nodoc:
73 74 75 |
# File 'lib/progress.rb', line 73 def @message end |
#start ⇒ Object
:nodoc:
57 58 59 |
# File 'lib/progress.rb', line 57 def start self. = '...' end |
#step ⇒ Object
:nodoc:
62 63 64 65 |
# File 'lib/progress.rb', line 62 def step @current += 1 self. = percent end |
#stop ⇒ Object
:nodoc:
68 69 70 |
# File 'lib/progress.rb', line 68 def stop self. = percent end |