Class: ProgressBar::Console
Instance Attribute Summary
Attributes inherited from Base
#error, #i, #max, #start, #text
Instance Method Summary collapse
- #change_error ⇒ Object
- #change_text ⇒ Object (also: #change_progress)
- #format_time(t) ⇒ Object
-
#initialize(*a) ⇒ Console
constructor
A new instance of Console.
Methods inherited from Base
#done_dur, #done_rel, #finish, #increment!, #total_dur
Constructor Details
#initialize(*a) ⇒ Console
Returns a new instance of Console.
59 60 61 62 |
# File 'lib/progress-bar.rb', line 59 def initialize *a super *a change_text end |
Instance Method Details
#change_error ⇒ Object
79 80 81 82 |
# File 'lib/progress-bar.rb', line 79 def change_error STDERR.printf "\r\e[J%s\n", error change_text end |
#change_text ⇒ Object Also known as: change_progress
72 73 74 75 76 |
# File 'lib/progress-bar.rb', line 72 def change_text l = (100.0*i/max).to_i dd, td = done_dur, total_dur STDOUT.printf "\r\e[J%s / %s [%s>%s] %s", format_time(dd), format_time(td), '='*l, ' '*[100, 100-l].min, text end |
#format_time(t) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/progress-bar.rb', line 64 def format_time t if t.finite? sprintf "%02d:%02d:%02d", t/3600, t/60 % 3600, t % 60 else "--:--:--" end end |