Class: ProgressBar

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Progress

#print_line, #update_last_line

Constructor Details

#initialize(max, logfilename) ⇒ ProgressBar

Returns a new instance of ProgressBar.



29
30
31
32
# File 'lib/progress.rb', line 29

def initialize(max, logfilename)
    super(logfilename)
    @max = max.to_f
end

Class Method Details

.logging(max, logfile, &block) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/progress.rb', line 73

def self.logging(max, logfile, &block)
  progress = ProgressBar.new(max, logfile)
  begin
    block.call(progress)
  ensure
    progress.print_line("Output written to #{logfile}")
  end
end

Instance Method Details

#processing_time(start_time, prior_processessing_time) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/progress.rb', line 43

def processing_time(start_time, prior_processessing_time)
  total_sec = prior_processessing_time + (Time.now().to_i - start_time)
  sec = total_sec
  days = sec / (3600*24)
  sec -= days * (3600*24)
  hours = sec / 3600
  sec -= hours * 3600
  min = sec / 60
  sec -= min * 60
  if days > 0 then
    return format("%d:%02d:%02d:%02d", days, hours, min, sec)
  else
    if hours > 0 then
      return format("%02d:%02d:%02d", hours, min, sec)
    else
      return format("%02d:%02d", min, sec)
    end
  end
end

#render_bar(current, length) ⇒ Object



38
39
40
41
# File 'lib/progress.rb', line 38

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

#report_progress(progress, start_time, prior_processessing_time, num_docs) ⇒ Object



63
64
65
66
67
68
69
70
71
# File 'lib/progress.rb', line 63

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

#set_max(value) ⇒ Object



34
35
36
# File 'lib/progress.rb', line 34

def set_max(value)
  @max = value.to_f
end