Class: PinterestDL::ProgressBar
- Inherits:
-
Object
- Object
- PinterestDL::ProgressBar
- Defined in:
- lib/pinterest_dl/progress_bar.rb
Instance Method Summary collapse
-
#initialize(total:, width: 30, out: $stdout) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #update(done) ⇒ Object
Constructor Details
#initialize(total:, width: 30, out: $stdout) ⇒ ProgressBar
Returns a new instance of ProgressBar.
6 7 8 9 10 |
# File 'lib/pinterest_dl/progress_bar.rb', line 6 def initialize(total:, width: 30, out: $stdout) @total = total.zero? ? 1 : total @width = width @out = out end |
Instance Method Details
#update(done) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/pinterest_dl/progress_bar.rb', line 12 def update(done) ratio = done.to_f / @total filled = (@width * ratio).round = ('#' * filled) + ('-' * (@width - filled)) @out.print "\r[#{}] #{done}/#{@total} (#{(ratio * 100).round}%)" @out.print "\n" if done >= @total @out.flush end |