Class: MultiProgressBar::Bar
- Inherits:
-
BarRenderer
- Object
- ProgressBar
- BarRenderer
- MultiProgressBar::Bar
- Defined in:
- lib/multi_progress_bar/bar.rb
Overview
Represents a progress bar at the bottom of the screen.
Bar
exposes the same interface as ProgressBar
from the progressbar
gem which backs its display.
file_progress = MultiProgressBar::Bar.new("file_1", 2596)
file_progress.inc # Increment value by 1.
file_progress.inc(10) # Increment value by 10.
file_progress.set(30) # Set value to 30.
# Change bar format.
file_progress.format = "%-14s (%s) %3d%% %s"
file_progress.format_arguments = [:title, :stat, :percentage, :bar].
See the ruby-progressbar
gem (0xcc.net/ruby-progressbar/index.html.en) for more details.
MultiProgressBar::Bar makes two additional format arguments available: :current and :total. These display the current and total values respectively.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#color ⇒ Object
Returns the value of attribute color.
Attributes inherited from BarRenderer
Instance Method Summary collapse
-
#finish ⇒ Object
Set the progress to 100% and display elapsed time instead of ETA.
-
#inc(step = 1) ⇒ Object
Increment the current value of the bar.
-
#initialize(title, total) ⇒ Bar
constructor
Create a new Bar with a
title
and atotal
value. -
#observe(&b) ⇒ Object
:nodoc:.
-
#set(count) ⇒ Object
Set the current value of the bar absolutely.
Methods inherited from BarRenderer
#do_percentage, #fmt_current, #fmt_total, #get_width, #restart, #show, #title=
Constructor Details
#initialize(title, total) ⇒ Bar
Create a new Bar with a title
and a total
value.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/multi_progress_bar/bar.rb', line 25 def initialize(title, total) MultiProgressBar.(self) @observers = [] @renderer = BarRenderer.new(title, total, MultiProgressBar.width) do || MultiProgressBar.(self, ) end super @renderer end |
Instance Attribute Details
#color ⇒ Object
Returns the value of attribute color.
22 23 24 |
# File 'lib/multi_progress_bar/bar.rb', line 22 def color @color end |
Instance Method Details
#finish ⇒ Object
Set the progress to 100% and display elapsed time instead of ETA.
50 51 52 53 |
# File 'lib/multi_progress_bar/bar.rb', line 50 def finish super notify_observers end |
#inc(step = 1) ⇒ Object
Increment the current value of the bar.
38 39 40 41 |
# File 'lib/multi_progress_bar/bar.rb', line 38 def inc(step = 1) super notify_observers end |
#observe(&b) ⇒ Object
:nodoc:
60 61 62 |
# File 'lib/multi_progress_bar/bar.rb', line 60 def observe(&b) #:nodoc: @observers << b end |
#set(count) ⇒ Object
Set the current value of the bar absolutely.
44 45 46 47 |
# File 'lib/multi_progress_bar/bar.rb', line 44 def set(count) super notify_observers end |