Class: SvgConform::QualityMetrics::QualityScore

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

Overview

Immutable value object representing a quality score and its classification.

Examples:

score = QualityScore.new(value: 85, level: :good)
score.good?                  # => true
score.acceptable?            # => true
score.grade                  # => "B"

Constant Summary collapse

LEVELS =
%i[excellent good fair poor critical].freeze
LEVEL_NEXT =
{
  critical: :poor,
  poor: :fair,
  fair: :good,
  good: :excellent,
  excellent: :excellent,
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(**args) ⇒ QualityScore

Returns a new instance of QualityScore.



21
22
23
24
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 21

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

Instance Method Details

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

Value equality



27
28
29
30
31
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 27

def ==(other)
  other.is_a?(QualityScore) &&
    value == other.value &&
    level == other.level
end

#acceptable?Boolean

Returns true if score indicates good quality.

Returns:

  • (Boolean)

    true if score indicates good quality



44
45
46
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 44

def acceptable?
  excellent? || good?
end

#gradeString

Returns Letter grade equivalent.

Returns:

  • (String)

    Letter grade equivalent



54
55
56
57
58
59
60
61
62
63
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 54

def grade
  case level
  when :excellent then "A"
  when :good then "B"
  when :fair then "C"
  when :poor then "D"
  when :critical then "F"
  else "?"
  end
end

#hashObject



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

def hash
  [value, level].hash
end

#next_levelSymbol

Returns Next better level, or self if already excellent.

Returns:

  • (Symbol)

    Next better level, or self if already excellent



74
75
76
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 74

def next_level
  LEVEL_NEXT[level] || :excellent
end

#problematic?Boolean

Returns true if score indicates problems.

Returns:

  • (Boolean)

    true if score indicates problems



49
50
51
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 49

def problematic?
  fair? || poor? || critical?
end