Class: HeadMusic::Style::GuideItemAssessment
- Inherits:
-
Object
- Object
- HeadMusic::Style::GuideItemAssessment
- Defined in:
- lib/head_music/style/guide_item_assessment.rb
Overview
One guide item applied to one voice: what the guideline found, and the standing the guide gave it.
A frozen value object that recomputes nothing, so it can be persisted or compared without the analysis machinery that produced it. Tier is stamped here because an item is shared between guides and has no single tier.
Strength is stamped for a different reason – an item does have a single strength – namely that a persisted assessment records the severity in force when it was graded, so re-classifying a guideline later cannot silently rewrite old grades. It defaults from the item, so the direct-construction sites in specs and any external consumer keep working, and it is normalized here as well: this is a seam a caller can reach without going through GuideItem, and an unvalidated value would surface as a bare KeyError from Strength.units, far from the construction that caused it.
Instance Attribute Summary collapse
-
#fitness ⇒ Object
readonly
Returns the value of attribute fitness.
-
#guide_item ⇒ Object
readonly
Returns the value of attribute guide_item.
-
#marks ⇒ Object
readonly
Returns the value of attribute marks.
-
#strength ⇒ Object
readonly
Returns the value of attribute strength.
-
#tier ⇒ Object
readonly
Returns the value of attribute tier.
-
#violation_key ⇒ Object
readonly
Returns the value of attribute violation_key.
-
#violation_values ⇒ Object
readonly
Returns the value of attribute violation_values.
-
#voice ⇒ Object
readonly
Returns the value of attribute voice.
Instance Method Summary collapse
-
#adherent? ⇒ Boolean
-
#end_position ⇒ Object
-
#gate? ⇒ Boolean
-
#initialize(voice:, guide_item:, tier:, marks:, fitness:, strength: guide_item.strength, violation_key: nil, violation_values: {}) ⇒ GuideItemAssessment
constructor
A new instance of GuideItemAssessment.
-
#message ⇒ Object
Nil when adherent: saying a violation anyway is how a consumer shows a student a rule they did not break.
-
#start_position ⇒ Object
Constructor Details
#initialize(voice:, guide_item:, tier:, marks:, fitness:, strength: guide_item.strength, violation_key: nil, violation_values: {}) ⇒ GuideItemAssessment
Returns a new instance of GuideItemAssessment.
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 24 def initialize(voice:, guide_item:, tier:, marks:, fitness:, strength: guide_item.strength, violation_key: nil, violation_values: {}) @voice = voice @guide_item = guide_item @tier = tier @strength = HeadMusic::Style::Guideline::Strength.normalized(strength, guide_item.name) @marks = [marks].flatten.compact.freeze @fitness = fitness @violation_key = violation_key @violation_values = violation_values freeze end |
Instance Attribute Details
#fitness ⇒ Object (readonly)
Returns the value of attribute fitness.
20 21 22 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 20 def fitness @fitness end |
#guide_item ⇒ Object (readonly)
Returns the value of attribute guide_item.
20 21 22 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 20 def guide_item @guide_item end |
#marks ⇒ Object (readonly)
Returns the value of attribute marks.
20 21 22 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 20 def marks @marks end |
#strength ⇒ Object (readonly)
Returns the value of attribute strength.
20 21 22 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 20 def strength @strength end |
#tier ⇒ Object (readonly)
Returns the value of attribute tier.
20 21 22 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 20 def tier @tier end |
#violation_key ⇒ Object (readonly)
Returns the value of attribute violation_key.
20 21 22 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 20 def violation_key @violation_key end |
#violation_values ⇒ Object (readonly)
Returns the value of attribute violation_values.
20 21 22 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 20 def violation_values @violation_values end |
#voice ⇒ Object (readonly)
Returns the value of attribute voice.
20 21 22 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 20 def voice @voice end |
Instance Method Details
#adherent? ⇒ Boolean
37 38 39 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 37 def adherent? fitness == 1 end |
#end_position ⇒ Object
58 59 60 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 58 def end_position marks.map(&:end_position).max end |
#gate? ⇒ Boolean
50 51 52 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 50 def gate? tier == :gate end |
#message ⇒ Object
Nil when adherent: saying a violation anyway is how a consumer shows a student a rule they did not break. Rendered through the guideline so this and GuideItem#violation_preview stay one seam.
44 45 46 47 48 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 44 def return if adherent? || violation_key.nil? guideline.render_template(violation_key, config, violation_values) end |
#start_position ⇒ Object
54 55 56 |
# File 'lib/head_music/style/guide_item_assessment.rb', line 54 def start_position marks.map(&:start_position).min end |