Sha256: 131aceadf12f33ed5fc46d995d37a64ede90b9c325d35120fd3b9d98cda200c7

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

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.length == 0
    start_position = placements.map { |placement| placement.position }.sort.first
    end_position = placements.map { |placement| placement.next_position }.sort.last
    new(start_position, end_position, placements: placements, fitness: fitness)
  end

  def self.for_each(placements, fitness: nil)
    placements = [placements].flatten
    placements.map { |placement| new(placement.position, placement.next_position, placements: placement, fitness: fitness) }
  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
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
head_music-0.14.8 lib/head_music/style/mark.rb
head_music-0.14.7 lib/head_music/style/mark.rb
head_music-0.14.5 lib/head_music/style/mark.rb
head_music-0.14.4 lib/head_music/style/mark.rb
head_music-0.14.2 lib/head_music/style/mark.rb
head_music-0.14.1 lib/head_music/style/mark.rb
head_music-0.13.2 lib/head_music/style/mark.rb
head_music-0.11.9 lib/head_music/style/mark.rb