Class: MultiProgressBar::BarRenderer

Inherits:
ProgressBar
  • Object
show all
Defined in:
lib/multi_progress_bar/bar_renderer.rb

Overview

:nodoc:

Direct Known Subclasses

Bar

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, total, width, &block) ⇒ BarRenderer

Returns a new instance of BarRenderer.



6
7
8
9
10
11
# File 'lib/multi_progress_bar/bar_renderer.rb', line 6

def initialize(title, total, width, &block)
  @block = block
  @buffer = StringIO.new
  @width = width
  super(title, total, @buffer)
end

Instance Attribute Details

#total=(value) ⇒ Object (writeonly)

Sets the attribute total

Parameters:

  • value

    the value to set the attribute total to.



3
4
5
# File 'lib/multi_progress_bar/bar_renderer.rb', line 3

def total=(value)
  @total = value
end

#widthObject

Returns the value of attribute width.



4
5
6
# File 'lib/multi_progress_bar/bar_renderer.rb', line 4

def width
  @width
end

Instance Method Details

#do_percentageObject



42
43
44
45
46
47
48
# File 'lib/multi_progress_bar/bar_renderer.rb', line 42

def do_percentage
  if @current.zero?
    0
  else
    super
  end
end

#fmt_currentObject



13
14
15
# File 'lib/multi_progress_bar/bar_renderer.rb', line 13

def fmt_current
  @current
end

#fmt_totalObject



17
18
19
# File 'lib/multi_progress_bar/bar_renderer.rb', line 17

def fmt_total
  @total
end

#get_widthObject



32
33
34
# File 'lib/multi_progress_bar/bar_renderer.rb', line 32

def get_width
  @width
end

#restartObject



36
37
38
39
40
# File 'lib/multi_progress_bar/bar_renderer.rb', line 36

def restart
  set(0)
  @start_time = Time.now
  @previous_time = @start_time
end

#showObject



21
22
23
24
25
# File 'lib/multi_progress_bar/bar_renderer.rb', line 21

def show
  super
  @block.call(@buffer.string)
  @buffer.string = ""
end

#title=(new_title) ⇒ Object



27
28
29
30
# File 'lib/multi_progress_bar/bar_renderer.rb', line 27

def title=(new_title)
  @title = new_title
  show
end