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

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

Class Method Details

.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.



23
24
25
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 23

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)



29
30
31
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 29

def maximum
  options.fetch(:maximum)
end

#messageObject



15
16
17
# File 'lib/head_music/style/guidelines/maximum_notes.rb', line 15

def message
  "Write up to #{maximum.humanize} notes."
end

#overageObject (private)



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

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