Class: HeadMusic::Style::Guidelines::MaximumNotes

Inherits:
HeadMusic::Style::Guideline show all
Defined in:
lib/head_music/style/guidelines/maximum_notes.rb

Overview

Flags a melody with more than the allowed number of notes. Configure the threshold with the factory, e.g. MaximumNotes.with(14).

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from HeadMusic::Style::Guideline

Class Method Details

.template_values(config) ⇒ Object

The count comes from the configuration or the class default – never from config alone, which is empty for the unconfigured case.



17
18
19
20
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 17

def self.template_values(config)
  count = config.fetch(:maximum)
  {count: count, number: HeadMusic::Style::Template.number_word(count)}
end

.with(maximum, **options) ⇒ Object



7
8
9
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 7

def self.with(maximum, **options)
  super(maximum: maximum, **options)
end

Instance Method Details

#fitness_denominatorObject (protected)

Score by the rate of overage notes rather than the raw count, so fitness is invariant to melody length.



26
27
28
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 26

def fitness_denominator
  notes.length
end

#marksObject



11
12
13
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 11

def marks
  HeadMusic::Style::Mark.for_each(notes[maximum..]) if overage.positive?
end

#maximumObject (private)



32
33
34
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 32

def maximum
  options.fetch(:maximum)
end

#overageObject (private)



36
37
38
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 36

def overage
  [notes.length - maximum, 0].max
end