Class: SvgConform::ExternalCheckers::Svgcheck::ReportComparator

Inherits:
Object
  • Object
show all
Defined in:
lib/svg_conform/external_checkers/svgcheck/report_comparator.rb

Overview

Sophisticated report comparison mechanism for svg_conform vs svgcheck

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_files_dir: "svgcheck/svgcheck/Tests", svgcheck_outputs_dir: "spec/fixtures/svgcheck") ⇒ ReportComparator

Returns a new instance of ReportComparator.



14
15
16
17
18
# File 'lib/svg_conform/external_checkers/svgcheck/report_comparator.rb', line 14

def initialize(test_files_dir: "svgcheck/svgcheck/Tests",
svgcheck_outputs_dir: "spec/fixtures/svgcheck")
  @test_files_dir = test_files_dir
  @svgcheck_outputs_dir = svgcheck_outputs_dir
end

Instance Attribute Details

#svgcheck_outputs_dirObject (readonly)

Returns the value of attribute svgcheck_outputs_dir.



12
13
14
# File 'lib/svg_conform/external_checkers/svgcheck/report_comparator.rb', line 12

def svgcheck_outputs_dir
  @svgcheck_outputs_dir
end

#test_files_dirObject (readonly)

Returns the value of attribute test_files_dir.



12
13
14
# File 'lib/svg_conform/external_checkers/svgcheck/report_comparator.rb', line 12

def test_files_dir
  @test_files_dir
end

Instance Method Details

#compare_all_test_filesObject

Compare all test files between svg_conform and svgcheck



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/svg_conform/external_checkers/svgcheck/report_comparator.rb', line 21

def compare_all_test_files
  test_files = find_test_files

  results = {
    total_files: test_files.length,
    matching: 0,
    different: 0,
    errors: 0,
    differences: {},
  }

  test_files.each do |filename|
    comparison = compare_file(filename)

    if comparison[:identical]
      results[:matching] += 1
    else
      results[:different] += 1
      results[:differences][filename] = comparison
    end
  rescue StandardError => e
    results[:errors] += 1
    results[:differences][filename] = {
      error: e.message,
      summary: "Error during comparison: #{e.message}",
    }
  end

  results
end

#compare_file(filename) ⇒ Object

Compare a single file between svg_conform and svgcheck



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/svg_conform/external_checkers/svgcheck/report_comparator.rb', line 53

def compare_file(filename)
  svg_conform_report = generate_svg_conform_report(filename)
  svgcheck_report = load_svgcheck_report(filename)

  unless svgcheck_report
    return { error: "No svgcheck report found",
             identical: false }
  end

  # Perform detailed comparison
  comparison = svg_conform_report.compare_with(svgcheck_report)

  # Add semantic comparison
  semantic_comparison = perform_semantic_comparison(svg_conform_report,
                                                    svgcheck_report)
  comparison[:semantic] = semantic_comparison

  comparison
end