Class: HeadMusic::Style::Guidelines::MaximumNotes
- Inherits:
-
HeadMusic::Style::Guideline
- Object
- HeadMusic::Style::Guideline
- HeadMusic::Style::Guidelines::MaximumNotes
- 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
-
.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.
-
.with(maximum, **options) ⇒ Object
Instance Method Summary collapse
-
#fitness_denominator ⇒ Object
protected
Score by the rate of overage notes rather than the raw count, so fitness is invariant to melody length.
-
#marks ⇒ Object
-
#maximum ⇒ Object
private
-
#overage ⇒ Object
private
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, **) super(maximum: maximum, **) end |
Instance Method Details
#fitness_denominator ⇒ Object (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 |
#marks ⇒ Object
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 |
#maximum ⇒ Object (private)
32 33 34 |
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 32 def maximum .fetch(:maximum) end |
#overage ⇒ Object (private)
36 37 38 |
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 36 def overage [notes.length - maximum, 0].max end |