Class: SvgConform::ValidationResult
- Inherits:
-
Object
- Object
- SvgConform::ValidationResult
- Defined in:
- lib/svg_conform/validation_result.rb
Overview
Represents the result of validating an SVG document
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#fixed_document ⇒ Object
readonly
Returns the value of attribute fixed_document.
-
#fixes_applied ⇒ Object
readonly
Returns the value of attribute fixes_applied.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#reference_manifest ⇒ Object
readonly
Returns the value of attribute reference_manifest.
-
#validity_errors ⇒ Object
readonly
Returns the value of attribute validity_errors.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #apply_fixes ⇒ Object
-
#available_ids ⇒ Object
Convenience accessors for manifest data.
- #error_count ⇒ Object
-
#export_manifest(format: :yaml) ⇒ Object
Export manifest separately for detailed analysis.
- #external_references ⇒ Object
- #failed_requirements ⇒ Object
- #fixable? ⇒ Boolean
- #fixable_count ⇒ Object
- #fixed? ⇒ Boolean
- #has_errors? ⇒ Boolean
- #has_external_references? ⇒ Boolean
- #has_warnings? ⇒ Boolean
-
#initialize(document, profile, context) ⇒ ValidationResult
constructor
A new instance of ValidationResult.
- #internal_references ⇒ Object
- #issue_count ⇒ Object
- #reference_statistics ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
- #to_s(format: :text) ⇒ Object
- #unresolved_internal_references ⇒ Object
- #valid? ⇒ Boolean
- #warning_count ⇒ Object
Constructor Details
#initialize(document, profile, context) ⇒ ValidationResult
Returns a new instance of ValidationResult.
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/svg_conform/validation_result.rb', line 11 def initialize(document, profile, context) @document = document @profile = profile @errors = context.errors @warnings = context.warnings @validity_errors = context.validity_errors @fixes_applied = [] @fixed_document = nil @reference_manifest = context.reference_manifest end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
8 9 10 |
# File 'lib/svg_conform/validation_result.rb', line 8 def document @document end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
8 9 10 |
# File 'lib/svg_conform/validation_result.rb', line 8 def errors @errors end |
#fixed_document ⇒ Object (readonly)
Returns the value of attribute fixed_document.
8 9 10 |
# File 'lib/svg_conform/validation_result.rb', line 8 def fixed_document @fixed_document end |
#fixes_applied ⇒ Object (readonly)
Returns the value of attribute fixes_applied.
8 9 10 |
# File 'lib/svg_conform/validation_result.rb', line 8 def fixes_applied @fixes_applied end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
8 9 10 |
# File 'lib/svg_conform/validation_result.rb', line 8 def profile @profile end |
#reference_manifest ⇒ Object (readonly)
Returns the value of attribute reference_manifest.
8 9 10 |
# File 'lib/svg_conform/validation_result.rb', line 8 def reference_manifest @reference_manifest end |
#validity_errors ⇒ Object (readonly)
Returns the value of attribute validity_errors.
8 9 10 |
# File 'lib/svg_conform/validation_result.rb', line 8 def validity_errors @validity_errors end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
8 9 10 |
# File 'lib/svg_conform/validation_result.rb', line 8 def warnings @warnings end |
Instance Method Details
#apply_fixes ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/svg_conform/validation_result.rb', line 87 def apply_fixes return self unless fixable? # Create a copy of the document for fixing @fixed_document = @document.dup @fixes_applied = [] # Apply fixes for errors first, then warnings fixable_issues = (@errors + @warnings).select(&:fixable?) fixable_issues.each do |issue| @fixes_applied << issue if issue.apply_fix end self end |
#available_ids ⇒ Object
Convenience accessors for manifest data
63 64 65 |
# File 'lib/svg_conform/validation_result.rb', line 63 def available_ids @reference_manifest.available_ids end |
#error_count ⇒ Object
42 43 44 |
# File 'lib/svg_conform/validation_result.rb', line 42 def error_count @errors.size end |
#export_manifest(format: :yaml) ⇒ Object
Export manifest separately for detailed analysis
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/svg_conform/validation_result.rb', line 135 def export_manifest(format: :yaml) case format when :yaml @reference_manifest.to_yaml when :json @reference_manifest.to_json when :hash @reference_manifest.to_h else @reference_manifest.to_yaml end end |
#external_references ⇒ Object
71 72 73 |
# File 'lib/svg_conform/validation_result.rb', line 71 def external_references @reference_manifest.external_references end |
#failed_requirements ⇒ Object
58 59 60 |
# File 'lib/svg_conform/validation_result.rb', line 58 def failed_requirements @errors.select(&:requirement_id) end |
#fixable? ⇒ Boolean
34 35 36 |
# File 'lib/svg_conform/validation_result.rb', line 34 def fixable? (@errors + @warnings).any?(&:fixable?) end |
#fixable_count ⇒ Object
54 55 56 |
# File 'lib/svg_conform/validation_result.rb', line 54 def fixable_count (@errors + @warnings).count(&:fixable?) end |
#fixed? ⇒ Boolean
38 39 40 |
# File 'lib/svg_conform/validation_result.rb', line 38 def fixed? !@fixed_document.nil? end |
#has_errors? ⇒ Boolean
26 27 28 |
# File 'lib/svg_conform/validation_result.rb', line 26 def has_errors? !@errors.empty? end |
#has_external_references? ⇒ Boolean
75 76 77 |
# File 'lib/svg_conform/validation_result.rb', line 75 def has_external_references? !@reference_manifest.external_references.empty? end |
#has_warnings? ⇒ Boolean
30 31 32 |
# File 'lib/svg_conform/validation_result.rb', line 30 def has_warnings? !@warnings.empty? end |
#internal_references ⇒ Object
67 68 69 |
# File 'lib/svg_conform/validation_result.rb', line 67 def internal_references @reference_manifest.internal_references end |
#issue_count ⇒ Object
50 51 52 |
# File 'lib/svg_conform/validation_result.rb', line 50 def issue_count error_count + warning_count end |
#reference_statistics ⇒ Object
83 84 85 |
# File 'lib/svg_conform/validation_result.rb', line 83 def reference_statistics @reference_manifest.statistics end |
#to_h ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/svg_conform/validation_result.rb', line 117 def to_h { file: @document&.file_path, profile: @profile.name, valid: valid?, errors: @errors.map(&:to_h), warnings: @warnings.map(&:to_h), fixes_applied: @fixes_applied.size, fixable: fixable_count, reference_manifest: @reference_manifest.to_h, } end |
#to_json(*args) ⇒ Object
130 131 132 |
# File 'lib/svg_conform/validation_result.rb', line 130 def to_json(*args) JSON.pretty_generate(to_h, *args) end |
#to_s(format: :text) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/svg_conform/validation_result.rb', line 104 def to_s(format: :text) case format when :text to_text when :json to_json when :hash to_h else to_text end end |
#unresolved_internal_references ⇒ Object
79 80 81 |
# File 'lib/svg_conform/validation_result.rb', line 79 def unresolved_internal_references @reference_manifest.unresolved_internal_references end |
#valid? ⇒ Boolean
22 23 24 |
# File 'lib/svg_conform/validation_result.rb', line 22 def valid? @errors.empty? && @validity_errors.empty? end |
#warning_count ⇒ Object
46 47 48 |
# File 'lib/svg_conform/validation_result.rb', line 46 def warning_count @warnings.size end |