class AdLint::ProgressMonitor

Attributes

location[R]
progress[R]

Public Class Methods

new(fpath, phase_num, verbose) click to toggle source
# File lib/adlint/monitor.rb, line 65
def initialize(fpath, phase_num, verbose)
  @fpath      = fpath
  @phase_num  = phase_num
  @verbose    = verbose
  @start_time = Time.now
  @cur_phase  = 0
end

Public Instance Methods

abort() click to toggle source
# File lib/adlint/monitor.rb, line 94
def abort
  draw_aborted
end
finish() click to toggle source
# File lib/adlint/monitor.rb, line 85
def finish
  @progress = @total
  if @cur_phase == @phase_num
    draw_finished
  else
    draw
  end
end
location=(loc) click to toggle source
# File lib/adlint/monitor.rb, line 98
def location=(loc)
  @location = loc
  if false && @fpath.identical?(@location.fpath)
    self.progress = @location.line_no
  end
end
progress=(val) click to toggle source
# File lib/adlint/monitor.rb, line 105
def progress=(val)
  @progress = val
  draw
end
start(title, total = 1) click to toggle source
# File lib/adlint/monitor.rb, line 76
def start(title, total = 1)
  @total    = total
  @title    = title
  @location = nil
  @progress = 0
  @cur_phase += 1
  draw
end

Private Instance Methods

draw() click to toggle source
# File lib/adlint/monitor.rb, line 111
def draw
  if @verbose
    draw_bar(@fpath, @title)
    print " %3d%%" % (total_progress * 100).to_i
  end
end
draw_aborted() click to toggle source
# File lib/adlint/monitor.rb, line 125
def draw_aborted
  if @verbose
    draw_bar(@fpath, @title)
    puts " %.3fs!" % (Time.now - @start_time)
  end
end
draw_bar(fpath, title) click to toggle source
# File lib/adlint/monitor.rb, line 138
def draw_bar(fpath, title)
  print "\r%30.30s [%3.3s] |" % [fpath.to_s.scan(/.{,30}\z/).first, title]
  print "=" * (28 * total_progress).to_i
  print " " * (28 - (28 * total_progress).to_i)
  print "|"
end
draw_finished() click to toggle source
# File lib/adlint/monitor.rb, line 118
def draw_finished
  if @verbose
    draw_bar(@fpath, "fin")
    puts " %.3fs" % (Time.now - @start_time)
  end
end
total_progress() click to toggle source
# File lib/adlint/monitor.rb, line 132
def total_progress
  phase_start    = (@cur_phase - 1).to_f / @phase_num
  phase_progress = @progress.to_f / @total / @phase_num
  phase_start + phase_progress
end