Class: SvgConform::ValidationIssue

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

Overview

Base class for validation issues

Instance Attribute Summary collapse

Instance Method Summary collapse

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
  @message = message
  @fix = fix
  @data = data
  @requirement_id_override = requirement_id
  @severity = severity
  @violation_type = violation_type || detect_violation_type
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



284
285
286
# File 'lib/svg_conform/validation_context.rb', line 284

def data
  @data
end

#fixObject (readonly)

Returns the value of attribute fix.



284
285
286
# File 'lib/svg_conform/validation_context.rb', line 284

def fix
  @fix
end

#messageObject (readonly)

Returns the value of attribute message.



284
285
286
# File 'lib/svg_conform/validation_context.rb', line 284

def message
  @message
end

#nodeObject (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_overrideObject (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

#ruleObject (readonly)

Returns the value of attribute rule.



284
285
286
# File 'lib/svg_conform/validation_context.rb', line 284

def rule
  @rule
end

#severityObject (readonly)

Returns the value of attribute severity.



284
285
286
# File 'lib/svg_conform/validation_context.rb', line 284

def severity
  @severity
end

#typeObject (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

Returns:

  • (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_fixObject



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

#columnObject



331
332
333
# File 'lib/svg_conform/validation_context.rb', line 331

def column
  @node.respond_to?(:column) ? @node.column : nil
end

#element_nameObject



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

Returns:

  • (Boolean)


315
316
317
# File 'lib/svg_conform/validation_context.rb', line 315

def error?
  @type == :error
end

#fixable?Boolean

Returns:

  • (Boolean)


323
324
325
# File 'lib/svg_conform/validation_context.rb', line 323

def fixable?
  !@fix.nil?
end

#lineObject



327
328
329
# File 'lib/svg_conform/validation_context.rb', line 327

def line
  @node.respond_to?(:line) ? @node.line : nil
end

#remediable?Boolean

Returns:

  • (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_confidenceObject



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_typeObject



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_idObject



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_actionObject



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_hObject



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: @message,
    line: line,
    column: column,
    element: element_name,
    fixable: fixable?,
  }
end

#to_sObject



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_typeObject



366
367
368
# File 'lib/svg_conform/validation_context.rb', line 366

def violation_type
  @violation_type
end

#warning?Boolean

Returns:

  • (Boolean)


319
320
321
# File 'lib/svg_conform/validation_context.rb', line 319

def warning?
  @type == :warning
end