Class: SvgConform::RemediationRunner
- Inherits:
-
Object
- Object
- SvgConform::RemediationRunner
- Defined in:
- lib/svg_conform/remediation_runner.rb
Overview
Runner for applying SvgConform remediations to SVG content
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
Instance Method Summary collapse
-
#available_remediations ⇒ Object
Get available remediations for the profile.
-
#has_remediations? ⇒ Boolean
Check if profile has any remediations available.
-
#initialize(profile: :svg_1_2_rfc, options: {}) ⇒ RemediationRunner
constructor
A new instance of RemediationRunner.
-
#run_remediation(svg_content, filename: nil) ⇒ Object
Run validation and remediation on SVG content.
-
#run_remediation_batch(file_paths) ⇒ Object
Run remediation on multiple files.
-
#run_remediation_file(file_path) ⇒ Object
Run remediation on a file.
Constructor Details
#initialize(profile: :svg_1_2_rfc, options: {}) ⇒ RemediationRunner
Returns a new instance of RemediationRunner.
12 13 14 15 16 17 18 |
# File 'lib/svg_conform/remediation_runner.rb', line 12 def initialize(profile: :svg_1_2_rfc, options: {}) @profile = resolve_profile(profile) = { verbose: false, strict: false, }.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
10 11 12 |
# File 'lib/svg_conform/remediation_runner.rb', line 10 def end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
10 11 12 |
# File 'lib/svg_conform/remediation_runner.rb', line 10 def profile @profile end |
Instance Method Details
#available_remediations ⇒ Object
Get available remediations for the profile
82 83 84 |
# File 'lib/svg_conform/remediation_runner.rb', line 82 def available_remediations @profile.remediations end |
#has_remediations? ⇒ Boolean
Check if profile has any remediations available
77 78 79 |
# File 'lib/svg_conform/remediation_runner.rb', line 77 def has_remediations? @profile.remediation_count.positive? end |
#run_remediation(svg_content, filename: nil) ⇒ Object
Run validation and remediation on SVG content
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 |
# File 'lib/svg_conform/remediation_runner.rb', line 21 def run_remediation(svg_content, filename: nil) # Parse the SVG content document = SvgConform::Document.from_content(svg_content) # Perform initial validation initial_validation = @profile.validate(document) # Create remediation engine remediation_engine = SvgConform::RemediationEngine.new(@profile) # Apply remediations if there are failures remediation_results = [] if initial_validation.failed_requirements.any? remediation_results = remediation_engine.apply_remediations(document, initial_validation) end # Perform final validation after remediations final_validation = @profile.validate(document) # Create result object RemediationRunResult.new( filename: filename, original_content: svg_content, remediated_content: document.to_xml, initial_validation: initial_validation, final_validation: final_validation, remediation_results: remediation_results, remediation_engine: remediation_engine, ) end |
#run_remediation_batch(file_paths) ⇒ Object
Run remediation on multiple files
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/svg_conform/remediation_runner.rb', line 64 def run_remediation_batch(file_paths) results = {} file_paths.each do |file_path| results[file_path] = run_remediation_file(file_path) rescue StandardError => e results[file_path] = create_error_result(file_path, e) end results end |
#run_remediation_file(file_path) ⇒ Object
Run remediation on a file
54 55 56 57 58 59 60 61 |
# File 'lib/svg_conform/remediation_runner.rb', line 54 def run_remediation_file(file_path) raise "File not found: #{file_path}" unless File.exist?(file_path) svg_content = File.read(file_path) filename = File.basename(file_path) run_remediation(svg_content, filename: filename) end |