class Lhm::Printer::Percentage

Public Class Methods

new() click to toggle source
Calls superclass method Lhm::Printer::Base::new
# File lib/lhm/printer.rb, line 16
def initialize
  super
  @max_length = 0
end

Public Instance Methods

end() click to toggle source
# File lib/lhm/printer.rb, line 27
def end
  write('100% complete')
  @output.write "\n"
end
exception(e) click to toggle source
# File lib/lhm/printer.rb, line 32
def exception(e)
  write("failed: #{e}")
  @output.write "\n"
end
notify(lowest, highest) click to toggle source
# File lib/lhm/printer.rb, line 21
def notify(lowest, highest)
  return if !highest || highest == 0
  message = "%.2f%% (#{lowest}/#{highest}) complete" % (lowest.to_f / highest * 100.0)
  write(message)
end

Private Instance Methods

write(message) click to toggle source
# File lib/lhm/printer.rb, line 39
def write(message)
  if (extra = @max_length - message.length) < 0
    @max_length = message.length
    extra = 0
  end

  @output.write "\r#{message}" + (' ' * extra)
end