Class: Lhm::Printer::Percentage

Inherits:
Object
  • Object
show all
Defined in:
lib/lhm/printer.rb

Instance Method Summary collapse

Constructor Details

#initializePercentage

Returns a new instance of Percentage.



16
17
18
# File 'lib/lhm/printer.rb', line 16

def initialize
  @max_length = 0
end

Instance Method Details

#endObject



33
34
35
# File 'lib/lhm/printer.rb', line 33

def end
  write('100% complete')
end

#exception(e) ⇒ Object



37
38
39
# File 'lib/lhm/printer.rb', line 37

def exception(e)
  Lhm.logger.error("failed: #{e}")
end

#notify(lowest, highest) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/lhm/printer.rb', line 20

def notify(lowest, highest)
  return if !highest || highest == 0

  # The argument lowest represents the next_to_insert row id, and highest represents the 
  # maximum id upto which chunker has to copy the data. 
  # If all the rows are inserted upto highest, then lowest passed here from chunker was 
  # highest + 1, which leads to the printer printing the progress > 100%.
  return if lowest >= highest
  
  message = "%.2f%% (#{lowest}/#{highest}) complete" % (lowest.to_f / highest * 100.0)
  write(message)
end