Class: HeadMusic::Style::GuideItemAssessment

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#fitnessObject (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_itemObject (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

#marksObject (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

#strengthObject (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

#tierObject (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_keyObject (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_valuesObject (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

#voiceObject (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

Returns:

  • (Boolean)


37
38
39
# File 'lib/head_music/style/guide_item_assessment.rb', line 37

def adherent?
  fitness == 1
end

#end_positionObject



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

Returns:

  • (Boolean)


50
51
52
# File 'lib/head_music/style/guide_item_assessment.rb', line 50

def gate?
  tier == :gate
end

#messageObject

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 message
  return if adherent? || violation_key.nil?

  guideline.render_template(violation_key, config, violation_values)
end

#start_positionObject



54
55
56
# File 'lib/head_music/style/guide_item_assessment.rb', line 54

def start_position
  marks.map(&:start_position).min
end