Sha256: 925f1bf67a3b0813959ba9d7398d243c40ed267c170a0a3142e34f3adcb38ff8

Contents?: true

Size: 749 Bytes

Versions: 9

Compression:

Stored size: 749 Bytes

Contents

# frozen_string_literal: true

# A module for style analysis and guidelines.
module HeadMusic::Style; end

# An analysis of music according to a style guide.
class HeadMusic::Style::Analysis
  attr_reader :guide, :voice

  def initialize(guide, voice)
    @guide = guide
    @voice = voice
  end

  def messages
    annotations.reject(&:adherent?).map(&:message)
  end
  alias_method :annotation_messages, :messages

  def annotations
    @annotations ||= @guide.analyze(voice)
  end

  def fitness
    return 1.0 if annotations.empty?

    @fitness ||= fitness_scores.inject(:+).to_f / fitness_scores.length
  end

  def adherent?
    fitness == 1
  end

  private

  def fitness_scores
    @fitness_scores ||= annotations.map(&:fitness)
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
head_music-4.0.1 lib/head_music/style/analysis.rb
head_music-4.0.0 lib/head_music/style/analysis.rb
head_music-3.0.1 lib/head_music/style/analysis.rb
head_music-3.0.0 lib/head_music/style/analysis.rb
head_music-2.0.1 lib/head_music/style/analysis.rb
head_music-2.0.0 lib/head_music/style/analysis.rb
head_music-1.0.0 lib/head_music/style/analysis.rb
head_music-0.29.0 lib/head_music/style/analysis.rb
head_music-0.28.0 lib/head_music/style/analysis.rb