Class: SvgConform::Errors::ValidationIssue
- Defined in:
- lib/svg_conform/errors/validation_issue.rb
Overview
Validation issue (error, warning, or notice)
Represents a single validation issue found during SVG validation. Contains information about the issue including type, rule, node, message, fix, and remediation information.
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#fix ⇒ Object
readonly
Returns the value of attribute fix.
-
#requirement_id_override ⇒ Object
readonly
Returns the value of attribute requirement_id_override.
-
#rule ⇒ Object
readonly
Returns the value of attribute rule.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#violation_type ⇒ Object
readonly
Returns the value of attribute violation_type.
Attributes inherited from Base
Instance Method Summary collapse
-
#affects_content? ⇒ Boolean
Check if this issue affects document content.
- #apply_fix ⇒ Object
- #column ⇒ Object
- #element_name ⇒ Object
- #error? ⇒ Boolean
- #fixable? ⇒ Boolean
-
#initialize(type:, rule:, node:, message:, fix: nil, data: {}, requirement_id: nil, severity: nil, violation_type: nil) ⇒ ValidationIssue
constructor
A new instance of ValidationIssue.
- #line ⇒ Object
-
#remediable? ⇒ Boolean
Check if this issue is remediable.
-
#remediation_confidence ⇒ Object
Get the confidence level of automated remediation.
-
#remediation_type ⇒ Object
Get the type of remediation needed.
- #requirement_id ⇒ Object
-
#suggested_action ⇒ Object
Get the suggested action to fix this issue.
- #to_h ⇒ Object
- #to_s ⇒ Object
- #warning? ⇒ Boolean
Constructor Details
#initialize(type:, rule:, node:, message:, fix: nil, data: {}, requirement_id: nil, severity: nil, violation_type: nil) ⇒ ValidationIssue
Returns a new instance of ValidationIssue.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 16 def initialize(type:, rule:, node:, message:, fix: nil, data: {}, requirement_id: nil, severity: nil, violation_type: nil) super(type: type, node: node, message: ) @rule = rule @fix = fix @data = data @requirement_id_override = requirement_id @severity = severity @violation_type = violation_type || detect_violation_type end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
13 14 15 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 13 def data @data end |
#fix ⇒ Object (readonly)
Returns the value of attribute fix.
13 14 15 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 13 def fix @fix end |
#requirement_id_override ⇒ Object (readonly)
Returns the value of attribute requirement_id_override.
13 14 15 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 13 def requirement_id_override @requirement_id_override end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
13 14 15 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 13 def rule @rule end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
13 14 15 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 13 def severity @severity end |
#violation_type ⇒ Object (readonly)
Returns the value of attribute violation_type.
13 14 15 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 13 def violation_type @violation_type end |
Instance Method Details
#affects_content? ⇒ Boolean
Check if this issue affects document content
150 151 152 153 154 155 156 157 158 159 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 150 def affects_content? case @violation_type when :content_violation, :reference_violation true when :color_violation, :font_violation, :style_violation, :viewbox_violation, :namespace_violation false else false end end |
#apply_fix ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 66 def apply_fix return false unless fixable? begin if @fix.respond_to?(:call) @fix.call else @fix.apply end true rescue StandardError false end end |
#column ⇒ Object
58 59 60 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 58 def column @node.respond_to?(:column) ? @node.column : nil end |
#element_name ⇒ Object
62 63 64 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 62 def element_name @node.respond_to?(:name) ? @node.name : nil end |
#error? ⇒ Boolean
42 43 44 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 42 def error? @type == :error end |
#fixable? ⇒ Boolean
50 51 52 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 50 def fixable? !@fix.nil? end |
#line ⇒ Object
54 55 56 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 54 def line @node.respond_to?(:line) ? @node.line : nil end |
#remediable? ⇒ Boolean
Check if this issue is remediable
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 82 def remediable? case @violation_type when :color_violation, :font_violation, :content_violation, :reference_violation, :namespace_violation, :viewbox_violation, :style_violation true when :structural_violation false else # Default to remediable for backward compatibility true end end |
#remediation_confidence ⇒ Object
Get the confidence level of automated remediation
112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 112 def remediation_confidence case @violation_type when :color_violation, :font_violation, :style_violation :automatic when :viewbox_violation, :namespace_violation :safe_structural when :content_violation, :reference_violation :safe_removal else :manual_review end end |
#remediation_type ⇒ Object
Get the type of remediation needed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 96 def remediation_type case @violation_type when :color_violation, :font_violation :convert when :content_violation, :reference_violation, :namespace_violation :remove when :viewbox_violation :add when :style_violation :promote else :unknown end end |
#requirement_id ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 27 def requirement_id return @requirement_id_override.to_s if @requirement_id_override if @rule.respond_to?(:id) @rule.id.to_s elsif @rule.respond_to?(:class) && @rule.class.respond_to?(:name) # Extract ID from class name for requirements class_name = @rule.class.name.split("::").last class_name.gsub(/Requirement$/, "").downcase.gsub(/([a-z])([A-Z])/, '\1_\2').downcase else "unknown" end end |
#suggested_action ⇒ Object
Get the suggested action to fix this issue
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 126 def suggested_action case @violation_type when :color_violation "Convert color to allowed equivalent using CssColor" when :font_violation "Map font family to generic equivalent" when :content_violation "Remove forbidden element or attribute" when :reference_violation "Remove broken reference or containing element" when :namespace_violation "Fix namespace declarations and remove invalid elements/attributes" when :viewbox_violation "Add missing viewBox attribute" when :style_violation "Promote style properties to attributes" when :structural_violation "Manual fix required - document structure issue" else "Apply available remediation" end end |
#to_h ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 161 def to_h { type: @type, rule: rule_id, message: @message, line: line, column: column, element: element_name, fixable: fixable?, remediable: remediable?, violation_type: @violation_type, remediation_type: remediation_type, remediation_confidence: remediation_confidence, suggested_action: suggested_action, affects_content: affects_content?, } end |
#to_s ⇒ Object
179 180 181 182 183 184 185 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 179 def to_s location = line ? " at line #{line}" : "" location += ":#{column}" if column rule_info = rule_id ? " (#{rule_id})" : "" remediation_info = remediable? ? " [#{remediation_type}]" : " [NOT REMEDIABLE]" "#{@message}#{location}#{rule_info}#{remediation_info}" end |
#warning? ⇒ Boolean
46 47 48 |
# File 'lib/svg_conform/errors/validation_issue.rb', line 46 def warning? @type == :warning end |