Sha256: b4b023e057d99311c93df1638eb2a8867a0e339fb5b4739c85e233ea6578cebf

Contents?: true

Size: 700 Bytes

Versions: 3

Compression:

Stored size: 700 Bytes

Contents

module HeadMusic::Style::Annotations
end

class HeadMusic::Style::Annotations::AtLeastEightNotes < HeadMusic::Style::Annotation
  MINIMUM_NOTES = 8

  def message
    "Write at least eight notes."
  end

  def marks
    placements.empty? ? no_placements_mark : deficiency_mark
  end

  private

  def no_placements_mark
    return Style::Mark.new(
      Position.new(composition, "1:1"),
      Position.new(composition, "2:1"),
      fitness: HeadMusic::PENALTY_FACTOR**MINIMUM_NOTES
    )
  end

  def deficiency_mark
    deficiency = [MINIMUM_NOTES - notes.length, 0].max
    if deficiency > 0
      Style::Mark.for_all(placements, fitness: HeadMusic::PENALTY_FACTOR**deficiency)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
head_music-0.11.3 lib/head_music/style/annotations/at_least_eight_notes.rb
head_music-0.11.2 lib/head_music/style/annotations/at_least_eight_notes.rb
head_music-0.11.1 lib/head_music/style/annotations/at_least_eight_notes.rb