Sha256: 456937ab3d323f013ae0ada7709d862cfa03bb46cc9c02e6e34239a946f8c455

Contents?: true

Size: 749 Bytes

Versions: 2

Compression:

Stored size: 749 Bytes

Contents

# frozen_string_literal: true

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

# An analysis of music according to a ruleset.
class HeadMusic::Style::Analysis
  attr_reader :ruleset, :subject

  def initialize(ruleset, subject)
    @ruleset = ruleset
    @subject = subject
  end

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

  def annotations
    @annotations ||= @ruleset.analyze(subject)
  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

2 entries across 2 versions & 1 rubygems

Version Path
head_music-0.19.0 lib/head_music/style/analysis.rb
head_music-0.18.0 lib/head_music/style/analysis.rb