Class: Legion::CLI::Chat::ProgressBar
- Inherits:
-
Object
- Object
- Legion::CLI::Chat::ProgressBar
- Defined in:
- lib/legion/cli/chat/progress_bar.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #advance(amount = 1) ⇒ Object
- #elapsed ⇒ Object
- #eta ⇒ Object
- #finish ⇒ Object
-
#initialize(total:, label: '', width: 40, output: $stdout) ⇒ ProgressBar
constructor
A new instance of ProgressBar.
- #percentage ⇒ Object
Constructor Details
#initialize(total:, label: '', width: 40, output: $stdout) ⇒ ProgressBar
Returns a new instance of ProgressBar.
9 10 11 12 13 14 15 16 |
# File 'lib/legion/cli/chat/progress_bar.rb', line 9 def initialize(total:, label: '', width: 40, output: $stdout) @total = [total, 1].max @current = 0 @label = label @width = width @output = output @start_time = Time.now end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
7 8 9 |
# File 'lib/legion/cli/chat/progress_bar.rb', line 7 def current @current end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
7 8 9 |
# File 'lib/legion/cli/chat/progress_bar.rb', line 7 def total @total end |
Instance Method Details
#advance(amount = 1) ⇒ Object
18 19 20 21 22 |
# File 'lib/legion/cli/chat/progress_bar.rb', line 18 def advance(amount = 1) @current = [@current + amount, @total].min render self end |
#elapsed ⇒ Object
35 36 37 |
# File 'lib/legion/cli/chat/progress_bar.rb', line 35 def elapsed Time.now - @start_time end |
#eta ⇒ Object
39 40 41 42 43 |
# File 'lib/legion/cli/chat/progress_bar.rb', line 39 def eta return 0 if @current.zero? || @current >= @total (elapsed / @current * (@total - @current)).round end |
#finish ⇒ Object
24 25 26 27 28 29 |
# File 'lib/legion/cli/chat/progress_bar.rb', line 24 def finish @current = @total render @output.puts self end |
#percentage ⇒ Object
31 32 33 |
# File 'lib/legion/cli/chat/progress_bar.rb', line 31 def percentage (@current.to_f / @total * 100).round(1) end |