Class: Legion::TTY::Components::ProgressPanel
- Inherits:
-
Object
- Object
- Legion::TTY::Components::ProgressPanel
- 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.
11 12 13 14 15 16 17 |
# File 'lib/legion/tty/components/progress_panel.rb', line 11 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.
9 10 11 |
# File 'lib/legion/tty/components/progress_panel.rb', line 9 def current @current end |
#title ⇒ Object (readonly)
Returns the value of attribute title.
9 10 11 |
# File 'lib/legion/tty/components/progress_panel.rb', line 9 def title @title end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
9 10 11 |
# File 'lib/legion/tty/components/progress_panel.rb', line 9 def total @total end |
Instance Method Details
#advance(step = 1) ⇒ Object
19 20 21 22 |
# File 'lib/legion/tty/components/progress_panel.rb', line 19 def advance(step = 1) @current = [@current + step, @total].min @bar&.advance(step) end |
#finish ⇒ Object
24 25 26 27 28 |
# File 'lib/legion/tty/components/progress_panel.rb', line 24 def finish remaining = @total - @current @bar&.advance(remaining) if remaining.positive? @current = @total end |
#finished? ⇒ Boolean
30 31 32 |
# File 'lib/legion/tty/components/progress_panel.rb', line 30 def finished? @current >= @total end |
#percent ⇒ Object
34 35 36 37 38 |
# File 'lib/legion/tty/components/progress_panel.rb', line 34 def percent return 0 if @total.zero? ((@current.to_f / @total) * 100).round(1) end |