Class: SvgConform::QualityMetrics::QualityResult

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

Overview

Immutable value object representing complete quality analysis result.

Combines all quality dimensions into a single value object.

Examples:

result = QualityResult.new(
  file_path: "image.svg",
  file_size_kb: 24.5,
  quality_score: QualityScore.new(value: 85, level: :good),
  error_breakdown: ErrorBreakdown.new(total: 3, ...),
  complexity: ComplexityMetrics.new(...),
  features: FeatureFlags.new(...),
  content_health: :good,
  size_category: :small
)

result.clean?                # => false
result.fixable?              # => true
result.to_report.render      # => Terminal colored output

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ QualityResult

Returns a new instance of QualityResult.



37
38
39
40
# File 'lib/svg_conform/quality_metrics/quality_result.rb', line 37

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

Instance Method Details

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

Value equality



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/svg_conform/quality_metrics/quality_result.rb', line 43

def ==(other)
  other.is_a?(QualityResult) &&
    file_path == other.file_path &&
    file_size_kb == other.file_size_kb &&
    quality_score == other.quality_score &&
    error_breakdown == other.error_breakdown &&
    complexity == other.complexity &&
    features == other.features &&
    content_health == other.content_health &&
    size_category == other.size_category
end

#clean?Boolean

Returns true if file has no errors.

Returns:

  • (Boolean)

    true if file has no errors



62
63
64
# File 'lib/svg_conform/quality_metrics/quality_result.rb', line 62

def clean?
  error_breakdown.clean?
end

#fixable?Boolean

Returns true if errors can be automatically fixed.

Returns:

  • (Boolean)

    true if errors can be automatically fixed



67
68
69
# File 'lib/svg_conform/quality_metrics/quality_result.rb', line 67

def fixable?
  error_breakdown.remediable.positive? && !error_breakdown.has_non_remediable?
end

#hashObject



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

def hash
  [file_path, file_size_kb, quality_score, error_breakdown,
   complexity, features, content_health, size_category].hash
end

#requires_manual_fix?Boolean

Returns true if file requires manual intervention.

Returns:

  • (Boolean)

    true if file requires manual intervention



72
73
74
# File 'lib/svg_conform/quality_metrics/quality_result.rb', line 72

def requires_manual_fix?
  error_breakdown.has_non_remediable?
end

#to_reportSvgConform::SvgQualityReport

Convert to SvgQualityReport for backward compatibility



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/svg_conform/quality_metrics/quality_result.rb', line 78

def to_report
  SvgQualityReport.new(
    file_path: file_path,
    quality_score: quality_score.value,
    quality_level: quality_score.level,
    error_count: error_breakdown.total,
    remediable_errors: error_breakdown.remediable,
    non_remediable_errors: error_breakdown.non_remediable,
    critical_errors: error_breakdown.critical,
    high_errors: error_breakdown.high,
    medium_errors: error_breakdown.medium,
    low_errors: error_breakdown.low,
    element_count: complexity.element_count,
    file_size_kb: file_size_kb,
    complexity_index: complexity.index,
    content_health: content_health,
    size_category: size_category,
    has_base64: features.has_base64,
    has_foreign_ns: features.has_foreign_ns,
    has_masks: features.has_masks,
    has_clip_paths: features.has_clip_paths,
    has_external_refs: features.has_external_refs,
  )
end