Class: RR::ScanReportPrinters::ScanSummaryReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/rubyrep/scan_report_printers/scan_summary_reporter.rb

Overview

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

Direct Known Subclasses

ScanDetailReporter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_, arg) ⇒ ScanSummaryReporter

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



28
29
30
# File 'lib/rubyrep/scan_report_printers/scan_summary_reporter.rb', line 28

def initialize(_, arg)
  self.only_totals = (arg != 'detailed')
end

Instance Attribute Details

#left_tableObject

Name of the left table of the current scan



17
18
19
# File 'lib/rubyrep/scan_report_printers/scan_summary_reporter.rb', line 17

def left_table
  @left_table
end

#only_totalsObject

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



14
15
16
# File 'lib/rubyrep/scan_report_printers/scan_summary_reporter.rb', line 14

def only_totals
  @only_totals
end

#right_tableObject

Name of the right table of the current scan



20
21
22
# File 'lib/rubyrep/scan_report_printers/scan_summary_reporter.rb', line 20

def right_table
  @right_table
end

#scan_resultObject

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

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


24
25
26
# File 'lib/rubyrep/scan_report_printers/scan_summary_reporter.rb', line 24

def scan_result
  @scan_result
end

Instance Method Details

#report_difference(type, row) ⇒ Object

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



65
66
67
# 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) ⇒ Object

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



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# 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_finishedObject

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.)



72
73
# File 'lib/rubyrep/scan_report_printers/scan_summary_reporter.rb', line 72

def scanning_finished
end