Class: ProgressBar

Inherits:
Progress show all
Defined in:
lib/progress.rb

Instance Method Summary collapse

Methods inherited from Progress

#print_line, #update_last_line

Constructor Details

#initialize(max) ⇒ ProgressBar

Returns a new instance of ProgressBar.



22
23
24
# File 'lib/progress.rb', line 22

def initialize(max)
    @max = max.to_f
end

Instance Method Details

#render_bar(current, length) ⇒ Object



26
27
28
29
# File 'lib/progress.rb', line 26

def render_bar(current, length)
    bars = (current.to_f * length.to_f).floor
    "=" * bars + ">" + " " * (length - bars)
end

#report_progress(progress) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/progress.rb', line 31

def report_progress(progress)
  if progress then
    current = (progress.to_f / @max)
    update_last_line("[#{render_bar(current, 40)}] combinations covered: #{progress}/#{@max} (#{format("%.8f", current * 100.0)}%)")
  else
    update_last_line("[... ? ... ? ... ? ...] combinations covered: ?/∞ (?%)")
  end
end