class MultiProgressBar::Bar

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.

Attributes

color[R]

Public Class Methods

new(title, total) click to toggle source

Create a new Bar with a title and a total value.

Calls superclass method
# File lib/ruby-multi-progressbar/bar.rb, line 25
def initialize(title, total)
  MultiProgressBar.add_bar(self)

  @observers = []

  @renderer = BarRenderer.new(title, total, MultiProgressBar.width) do |rendered_bar|
    MultiProgressBar.update_bar(self, rendered_bar)
  end

  super @renderer
end

Public Instance Methods

color=(color) click to toggle source
# File lib/ruby-multi-progressbar/bar.rb, line 55
def color=(color)
  @color = color
  show
end
finish() click to toggle source

Set the progress to 100% and display elapsed time instead of ETA.

Calls superclass method
# File lib/ruby-multi-progressbar/bar.rb, line 50
def finish
  super
  notify_observers
end
inc(step = 1) click to toggle source

Increment the current value of the bar.

Calls superclass method
# File lib/ruby-multi-progressbar/bar.rb, line 38
def inc(step = 1)
  super
  notify_observers
end
set(count) click to toggle source

Set the current value of the bar absolutely.

Calls superclass method
# File lib/ruby-multi-progressbar/bar.rb, line 44
def set(count)
  super
  notify_observers
end

Private Instance Methods

notify_observers() click to toggle source
# File lib/ruby-multi-progressbar/bar.rb, line 65
def notify_observers
  @observers.each { |b| b.call(self) }
end