class Hydra::Listener::ProgressBar

Output a progress bar as files are completed

Public Instance Methods

file_end(file, output) click to toggle source

Increment completed files count and update bar

# File lib/hydra/listener/progress_bar.rb, line 15
def file_end(file, output)
  unless output == '.'
    @output.write "\r#{' '*60}\r#{output}\n"
    @errors = true
  end
  @files_completed += 1
  render_progress_bar
end
testing_begin(files) click to toggle source

Store the total number of files

# File lib/hydra/listener/progress_bar.rb, line 6
def testing_begin(files)
  @total_files = files.size
  @files_completed = 0
  @test_output = ""
  @errors = false
  render_progress_bar
end
testing_end() click to toggle source

Break the line

# File lib/hydra/listener/progress_bar.rb, line 25
def testing_end
  render_progress_bar
  @output.write "\n"
end

Private Instance Methods

render_progress_bar() click to toggle source
# File lib/hydra/listener/progress_bar.rb, line 32
def render_progress_bar
  width = 30
  complete = ((@files_completed.to_f / @total_files.to_f) * width).to_i
  @output.write "\r" # move to beginning
  @output.write 'Hydra Testing ['
  @output.write @errors ? "\0033[0;31m" : "\0033[0;32m"
  complete.times{@output.write '#'}
  @output.write '>'
  (width-complete).times{@output.write ' '}
  @output.write "\0033[0m"
  @output.write "] #{@files_completed}/#{@total_files}"
  @output.flush
end