Sha256: cf90c5cff142488ab0c1ddfb64b36b9b3443bcbe3eceb3286e37a2185cad0502

Contents?: true

Size: 739 Bytes

Versions: 18

Compression:

Stored size: 739 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 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

18 entries across 18 versions & 1 rubygems

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