Class: SvgConform::QualityMetrics::QualityScore
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- SvgConform::QualityMetrics::QualityScore
- Defined in:
- lib/svg_conform/quality_metrics/quality_score.rb
Overview
Immutable value object representing a quality score and its classification.
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
-
#==(other) ⇒ Object
(also: #eql?)
Value equality.
-
#acceptable? ⇒ Boolean
True if score indicates good quality.
-
#grade ⇒ String
Letter grade equivalent.
- #hash ⇒ Object
-
#initialize(**args) ⇒ QualityScore
constructor
A new instance of QualityScore.
-
#next_level ⇒ Symbol
Next better level, or self if already excellent.
-
#problematic? ⇒ Boolean
True if score indicates problems.
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.
44 45 46 |
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 44 def acceptable? excellent? || good? end |
#grade ⇒ String
Returns 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 |
#hash ⇒ Object
34 35 36 |
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 34 def hash [value, level].hash end |
#next_level ⇒ Symbol
Returns 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.
49 50 51 |
# File 'lib/svg_conform/quality_metrics/quality_score.rb', line 49 def problematic? fair? || poor? || critical? end |