class RR::ScanReportPrinters::ScanSummaryReporter

A ScanReportPrinter producing a summary (number of differences) only.

Attributes

left_table[RW]

Name of the left table of the current scan

only_totals[RW]

Set to true if only the total number of differences should be reported

right_table[RW]

Name of the right table of the current scan

scan_result[RW]

Hold the result of the current scan. A hash with a running count of

+:conflict+, +:left+ (only) or +:right+ (only) records.

Public Class Methods

new(_, arg) click to toggle source

A scan run is to be started using this scan result printer. arg is the command line argument as yielded by OptionParser#on.

# File lib/rubyrep/scan_report_printers/scan_summary_reporter.rb, line 28
def initialize(_, arg)
  self.only_totals = (arg != 'detailed')
end

Public Instance Methods

report_difference(type, row) click to toggle source

Each difference is handed to the printer as described in the format as described e. g. in DirectTableScan#run

# File lib/rubyrep/scan_report_printers/scan_summary_reporter.rb, line 65
def report_difference(type, row)
  scan_result[type] += 1
end
scan(left_table, right_table) { || ... } click to toggle source

A scan of the given 'left' table and corresponding 'right' table is executed. Needs to yield so that the actual scan can be executed.

# File lib/rubyrep/scan_report_printers/scan_summary_reporter.rb, line 34
def scan(left_table, right_table)
  self.left_table = left_table
  self.right_table = right_table
  self.scan_result = {:conflict => 0, :left => 0, :right => 0}

  header = left_table.clone
  header << " / " << right_table if left_table != right_table
  $stdout.write "#{header.rjust(36)} "

  yield # Give control back so that the actual table scan can be done.

  if only_totals
    $stdout.write \
      "#{rjust_value(scan_result[:conflict] + scan_result[:left] + scan_result[:right])}"
  else
    $stdout.write \
      "#{rjust_value(scan_result[:conflict])} " +
      "#{rjust_value(scan_result[:left])} " +
      "#{rjust_value(scan_result[:right])}"
  end
  $stdout.puts
end
scanning_finished() click to toggle source

Optional method. If a scan report printer has it, it is called after the last table scan is executed. (A good place to print a final summary.)

# File lib/rubyrep/scan_report_printers/scan_summary_reporter.rb, line 72
def scanning_finished
end

Private Instance Methods

rjust_value(value) click to toggle source

Right adjusts the given number and returns according string.

# File lib/rubyrep/scan_report_printers/scan_summary_reporter.rb, line 58
def rjust_value(value)
  value.to_s.rjust(3)
end