Class: SvgConform::QualityMetrics::ErrorBreakdown

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/svg_conform/quality_metrics/error_breakdown.rb

Overview

Immutable value object representing error breakdown by severity and remediability.

Examples:

breakdown = ErrorBreakdown.new(
  total: 15,
  critical: 1,
  high: 3,
  medium: 8,
  low: 3,
  remediable: 12,
  non_remediable: 3
)

breakdown.clean?              # => false
breakdown.worst_severity     # => :critical

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ ErrorBreakdown

Ensure immutability after initialization



33
34
35
36
# File 'lib/svg_conform/quality_metrics/error_breakdown.rb', line 33

def initialize(**args)
  super(args)
  freeze
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

Value equality



39
40
41
42
43
44
45
46
47
48
# File 'lib/svg_conform/quality_metrics/error_breakdown.rb', line 39

def ==(other)
  other.is_a?(ErrorBreakdown) &&
    total == other.total &&
    critical == other.critical &&
    high == other.high &&
    medium == other.medium &&
    low == other.low &&
    remediable == other.remediable &&
    non_remediable == other.non_remediable
end

#clean?Boolean

Returns true if there are no errors.

Returns:

  • (Boolean)

    true if there are no errors



56
57
58
# File 'lib/svg_conform/quality_metrics/error_breakdown.rb', line 56

def clean?
  total.zero?
end

#has_critical?Boolean

Returns true if any critical errors exist.

Returns:

  • (Boolean)

    true if any critical errors exist



61
62
63
# File 'lib/svg_conform/quality_metrics/error_breakdown.rb', line 61

def has_critical?
  critical.positive?
end

#has_non_remediable?Boolean

Returns true if any non-remediable errors exist.

Returns:

  • (Boolean)

    true if any non-remediable errors exist



66
67
68
# File 'lib/svg_conform/quality_metrics/error_breakdown.rb', line 66

def has_non_remediable?
  non_remediable.positive?
end

#hashObject



51
52
53
# File 'lib/svg_conform/quality_metrics/error_breakdown.rb', line 51

def hash
  [total, critical, high, medium, low, remediable, non_remediable].hash
end

#worst_severitySymbol

Returns Worst severity level present.

Returns:

  • (Symbol)

    Worst severity level present



71
72
73
74
75
76
77
78
79
80
# File 'lib/svg_conform/quality_metrics/error_breakdown.rb', line 71

def worst_severity
  return :none if clean?

  return :critical if critical.positive?
  return :high if high.positive?
  return :medium if medium.positive?
  return :low if low.positive?

  :none
end