Class: SvgConform::ValidationIssue
- Inherits:
-
Object
- Object
- SvgConform::ValidationIssue
- Defined in:
- lib/svg_conform/validation_context.rb
Overview
Base class for validation issues
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#fix ⇒ Object
readonly
Returns the value of attribute fix.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#node ⇒ Object
readonly
Returns the value of attribute node.
-
#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.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Instance Method Summary collapse
- #affects_content? ⇒ Boolean
- #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
- #remediation_confidence ⇒ Object
- #remediation_type ⇒ Object
- #requirement_id ⇒ Object
- #suggested_action ⇒ Object
- #to_h ⇒ Object
- #to_s ⇒ Object
- #violation_type ⇒ 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.
287 288 289 290 291 292 293 294 295 296 297 298 |
# File 'lib/svg_conform/validation_context.rb', line 287 def initialize(type:, rule:, node:, message:, fix: nil, data: {}, requirement_id: nil, severity: nil, violation_type: nil) @type = type @rule = rule @node = node = @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.
284 285 286 |
# File 'lib/svg_conform/validation_context.rb', line 284 def data @data end |
#fix ⇒ Object (readonly)
Returns the value of attribute fix.
284 285 286 |
# File 'lib/svg_conform/validation_context.rb', line 284 def fix @fix end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
284 285 286 |
# File 'lib/svg_conform/validation_context.rb', line 284 def end |
#node ⇒ Object (readonly)
Returns the value of attribute node.
284 285 286 |
# File 'lib/svg_conform/validation_context.rb', line 284 def node @node end |
#requirement_id_override ⇒ Object (readonly)
Returns the value of attribute requirement_id_override.
284 285 286 |
# File 'lib/svg_conform/validation_context.rb', line 284 def requirement_id_override @requirement_id_override end |
#rule ⇒ Object (readonly)
Returns the value of attribute rule.
284 285 286 |
# File 'lib/svg_conform/validation_context.rb', line 284 def rule @rule end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
284 285 286 |
# File 'lib/svg_conform/validation_context.rb', line 284 def severity @severity end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
284 285 286 |
# File 'lib/svg_conform/validation_context.rb', line 284 def type @type end |
Instance Method Details
#affects_content? ⇒ Boolean
434 435 436 437 438 439 440 441 442 443 |
# File 'lib/svg_conform/validation_context.rb', line 434 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
339 340 341 342 343 344 345 346 347 348 349 350 351 352 |
# File 'lib/svg_conform/validation_context.rb', line 339 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
331 332 333 |
# File 'lib/svg_conform/validation_context.rb', line 331 def column @node.respond_to?(:column) ? @node.column : nil end |
#element_name ⇒ Object
335 336 337 |
# File 'lib/svg_conform/validation_context.rb', line 335 def element_name @node.respond_to?(:name) ? @node.name : nil end |
#error? ⇒ Boolean
315 316 317 |
# File 'lib/svg_conform/validation_context.rb', line 315 def error? @type == :error end |
#fixable? ⇒ Boolean
323 324 325 |
# File 'lib/svg_conform/validation_context.rb', line 323 def fixable? !@fix.nil? end |
#line ⇒ Object
327 328 329 |
# File 'lib/svg_conform/validation_context.rb', line 327 def line @node.respond_to?(:line) ? @node.line : nil end |
#remediable? ⇒ Boolean
370 371 372 373 374 375 376 377 378 379 380 381 |
# File 'lib/svg_conform/validation_context.rb', line 370 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
398 399 400 401 402 403 404 405 406 407 408 409 |
# File 'lib/svg_conform/validation_context.rb', line 398 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
383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
# File 'lib/svg_conform/validation_context.rb', line 383 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
300 301 302 303 304 305 306 307 308 309 310 311 312 313 |
# File 'lib/svg_conform/validation_context.rb', line 300 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
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/svg_conform/validation_context.rb', line 411 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
354 355 356 357 358 359 360 361 362 363 364 |
# File 'lib/svg_conform/validation_context.rb', line 354 def to_h { type: @type, rule: rule_id, message: , line: line, column: column, element: element_name, fixable: fixable?, } end |
#to_s ⇒ Object
445 446 447 448 449 450 451 |
# File 'lib/svg_conform/validation_context.rb', line 445 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 |
#violation_type ⇒ Object
366 367 368 |
# File 'lib/svg_conform/validation_context.rb', line 366 def violation_type @violation_type end |
#warning? ⇒ Boolean
319 320 321 |
# File 'lib/svg_conform/validation_context.rb', line 319 def warning? @type == :warning end |