Class: MultiProgressBar::TotalBar

Inherits:
Bar show all
Defined in:
lib/multi_progress_bar/total_bar.rb

Overview

Works just like Bar, but displays the total of other bars. TotalBar#inc and TotalBar#set don’t work.

Instance Attribute Summary

Attributes inherited from Bar

#color

Attributes inherited from BarRenderer

#total, #width

Instance Method Summary collapse

Methods inherited from Bar

#finish, #inc, #observe, #set

Methods inherited from BarRenderer

#do_percentage, #fmt_current, #fmt_total, #get_width, #restart, #show, #title=

Constructor Details

#initialize(title, bars = MultiProgressBar.bars.dup) ⇒ TotalBar

Create a new TotalBar. bars is an array of Bar objects, and defaults to all existing bars.



7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/multi_progress_bar/total_bar.rb', line 7

def initialize(title, bars = MultiProgressBar.bars.dup)
  @bars = bars

  @bars.each do |bar|
    bar.observe do
      update_total
    end
  end

  total_total = @bars.inject(0) { |sum, bar| sum + bar.total }
  super title, total_total
end