Sha256: 85d41b10fc141fb4f3f15783dbef8981a7d61262c71b3a25fe7eacf4b0748a47

Contents?: true

Size: 730 Bytes

Versions: 3

Compression:

Stored size: 730 Bytes

Contents

# frozen_string_literal: true

# Module for style guidelines.
module HeadMusic::Style::Guidelines; end

# A counterpoint guideline
class HeadMusic::Style::Guidelines::AtLeastEightNotes < HeadMusic::Style::Annotation
  MINIMUM_NOTES = 8

  MESSAGE = 'Write at least eight notes.'

  def marks
    placements.empty? ? no_placements_mark : deficiency_mark
  end

  private

  def no_placements_mark
    HeadMusic::Style::Mark.new(
      HeadMusic::Position.new(composition, '1:1'),
      HeadMusic::Position.new(composition, '2:1'),
      fitness: 0
    )
  end

  def deficiency_mark
    return unless notes.length < MINIMUM_NOTES
    HeadMusic::Style::Mark.for_all(placements, fitness: notes.length.to_f / MINIMUM_NOTES)
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
head_music-0.20.0 lib/head_music/style/guidelines/at_least_eight_notes.rb
head_music-0.19.2 lib/head_music/style/guidelines/at_least_eight_notes.rb
head_music-0.19.1 lib/head_music/style/guidelines/at_least_eight_notes.rb