Class: Legion::TTY::Components::ProgressPanel
- Inherits:
-
Object
- Object
- Legion::TTY::Components::ProgressPanel
- Includes:
- Logging::Helper
- Defined in:
- lib/legion/tty/components/progress_panel.rb
Instance Attribute Summary collapse
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#title ⇒ Object
readonly
Returns the value of attribute title.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #advance(step = 1) ⇒ Object
- #finish ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(title:, total:, output: $stdout) ⇒ ProgressPanel
constructor
A new instance of ProgressPanel.
- #percent ⇒ Object
- #render(width: 80) ⇒ Object
Constructor Details
#initialize(title:, total:, output: $stdout) ⇒ ProgressPanel
Returns a new instance of ProgressPanel.
14 15 16 17 18 19 20 |
# File 'lib/legion/tty/components/progress_panel.rb', line 14 def initialize(title:, total:, output: $stdout) @title = title @total = total @current = 0 @output = output @bar = end |
Instance Attribute Details
#current ⇒ Object (readonly)
Returns the value of attribute current.
12 13 14 |
# File 'lib/legion/tty/components/progress_panel.rb', line 12 def current @current end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
12 13 14 |
# File 'lib/legion/tty/components/progress_panel.rb', line 12 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
12 13 14 |
# File 'lib/legion/tty/components/progress_panel.rb', line 12 def total @total end |
Instance Method Details
#advance(step = 1) ⇒ Object
22 23 24 25 |
# File 'lib/legion/tty/components/progress_panel.rb', line 22 def advance(step = 1) @current = [@current + step, @total].min @bar&.advance(step) end |
#finish ⇒ Object
27 28 29 30 31 |
# File 'lib/legion/tty/components/progress_panel.rb', line 27 def finish remaining = @total - @current @bar&.advance(remaining) if remaining.positive? @current = @total end |
#finished? ⇒ Boolean
33 34 35 |
# File 'lib/legion/tty/components/progress_panel.rb', line 33 def finished? @current >= @total end |
#percent ⇒ Object
37 38 39 40 41 |
# File 'lib/legion/tty/components/progress_panel.rb', line 37 def percent return 0 if @total.zero? ((@current.to_f / @total) * 100).round(1) end |