Class: RubyRich::ProgressBar
- Inherits:
-
Object
- Object
- RubyRich::ProgressBar
- Defined in:
- lib/ruby_rich/progress_bar.rb
Instance Attribute Summary collapse
-
#progress ⇒ Object
readonly
Returns the value of attribute progress.
Instance Method Summary collapse
- #advance(amount) ⇒ Object
-
#initialize(total, width: 50, style: :default) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #render ⇒ Object
Constructor Details
#initialize(total, width: 50, style: :default) ⇒ ProgressBar
Returns a new instance of ProgressBar.
6 7 8 9 10 11 |
# File 'lib/ruby_rich/progress_bar.rb', line 6 def initialize(total, width: 50, style: :default) @total = total @progress = 0 @width = width @style = style end |
Instance Attribute Details
#progress ⇒ Object (readonly)
Returns the value of attribute progress.
4 5 6 |
# File 'lib/ruby_rich/progress_bar.rb', line 4 def progress @progress end |
Instance Method Details
#advance(amount) ⇒ Object
13 14 15 16 17 |
# File 'lib/ruby_rich/progress_bar.rb', line 13 def advance(amount) @progress += amount @progress = @total if @progress > @total render end |
#render ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/ruby_rich/progress_bar.rb', line 19 def render percentage = (@progress.to_f / @total * 100).to_i completed_width = (@progress.to_f / @total * @width).to_i incomplete_width = @width - completed_width = "[#{"=" * completed_width}#{" " * incomplete_width}]" print "\r#{} #{percentage}%" puts if @progress == @total end |