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.



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

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

Class Method Details

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



79
80
81
82
83
84
85
86
# File 'lib/progress.rb', line 79

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



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/progress.rb', line 49

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



44
45
46
47
# File 'lib/progress.rb', line 44

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



69
70
71
72
73
74
75
76
77
# File 'lib/progress.rb', line 69

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



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

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