Sha256: 710e9ad5bbefc86cebf0d39a608263bb7be386e8d2babc3052ec3f7f11b6c53e

Contents?: true

Size: 1.28 KB

Versions: 18

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

# A mark is a fragment of music with an optional fitness score assigned.
# Marks are collected into annotations which comment on a voice.
class HeadMusic::Style::Mark
  attr_reader :start_position, :end_position, :placements, :fitness

  def self.for(placement, fitness: nil)
    new(placement.position, placement.next_position, placements: [placement], fitness: fitness)
  end

  def self.for_all(placements, fitness: nil)
    placements = [placements].flatten.compact
    return [] if placements.empty?

    start_position = placements.map(&:position).min
    end_position = placements.map(&:next_position).max
    new(start_position, end_position, placements: placements, fitness: fitness)
  end

  def self.for_each(placements, fitness: nil)
    placements = [placements].flatten
    placements.map do |placement|
      new(placement.position, placement.next_position, placements: placement, fitness: fitness)
    end
  end

  def initialize(start_position, end_position, placements: [], fitness: nil)
    @start_position = start_position
    @end_position = end_position
    @placements = [placements].flatten.compact
    @fitness = fitness || HeadMusic::PENALTY_FACTOR
  end

  def code
    [start_position, end_position].join(' to ')
  end

  def to_s
    code
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
head_music-0.27.0 lib/head_music/style/mark.rb
head_music-0.26.3 lib/head_music/style/mark.rb
head_music-0.26.2 lib/head_music/style/mark.rb
head_music-0.26.1 lib/head_music/style/mark.rb
head_music-0.26.0 lib/head_music/style/mark.rb
head_music-0.25.0 lib/head_music/style/mark.rb
head_music-0.24.5 lib/head_music/style/mark.rb
head_music-0.24.4 lib/head_music/style/mark.rb
head_music-0.24.3 lib/head_music/style/mark.rb
head_music-0.24.2 lib/head_music/style/mark.rb
head_music-0.24.1 lib/head_music/style/mark.rb
head_music-0.24.0 lib/head_music/style/mark.rb
head_music-0.23.4 lib/head_music/style/mark.rb
head_music-0.23.3 lib/head_music/style/mark.rb
head_music-0.23.2 lib/head_music/style/mark.rb
head_music-0.23.1 lib/head_music/style/mark.rb
head_music-0.23.0 lib/head_music/style/mark.rb
head_music-0.22.0 lib/head_music/style/mark.rb