Class: SvgConform::Commands::SvgcheckCompare

Inherits:
Object
  • Object
show all
Defined in:
lib/svg_conform/commands/svgcheck_compare.rb

Overview

Compare command for comparing SvgConform validation with svgcheck reports

Defined Under Namespace

Classes: CompareError

Instance Method Summary collapse

Constructor Details

#initialize(file, options) ⇒ SvgcheckCompare

Returns a new instance of SvgcheckCompare.



11
12
13
14
15
# File 'lib/svg_conform/commands/svgcheck_compare.rb', line 11

def initialize(file, options)
  @file = file
  @options = options
  # Paint doesn't need initialization like Pastel
end

Instance Method Details

#executeObject



17
18
19
20
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
51
52
# File 'lib/svg_conform/commands/svgcheck_compare.rb', line 17

def execute
  # Determine the correct file to validate
  validation_file = determine_validation_file(@file)

  unless File.exist?(validation_file)
    raise CompareError, "File '#{validation_file}' not found"
  end

  # Find or use specified svgcheck report
  svgcheck_report_path = find_svgcheck_report
  unless svgcheck_report_path && File.exist?(svgcheck_report_path)
    raise CompareError,
          "svgcheck report not found#{" - expected: #{svgcheck_report_path}" if svgcheck_report_path}"
  end

  # Load svgcheck report using the new external checker parser
  parser = SvgConform::ExternalCheckers::Svgcheck::Parser.new
  error_content = File.read(svgcheck_report_path)
  svgcheck_report = parser.parse(error_content, nil,
                                 filename: File.basename(@file))

  # Generate SvgConform report using the correct validation file
  validator = SvgConform::Validator.new
  result = validator.validate_file(validation_file,
                                   profile: @options[:profile].to_sym)
  svg_conform_report = SvgConform::ConformanceReport.from_svg_conform_result(
    File.basename(@file),
    result,
    profile: @options[:profile].to_sym,
  )

  # Compare the reports
  comparator = SvgConform::ReportComparator.new
  comparator.compare_reports(svg_conform_report, svgcheck_report,
                             File.basename(@file))
end