lib/head_music/style/analysis.rb in head_music-0.17.0 vs lib/head_music/style/analysis.rb in head_music-0.18.0

- old
+ new

@@ -1,36 +1,38 @@ -module HeadMusic - module Style - class Analysis - attr_reader :ruleset, :subject, :annotations +# frozen_string_literal: true - def initialize(ruleset, subject) - @ruleset = ruleset - @subject = subject - end +# A module for style analysis and rules. +module HeadMusic::Style; end - def messages - annotations.reject(&:adherent?).map(&:message) - end - alias_method :annotation_messages, :messages +# An analysis of music according to a ruleset. +class HeadMusic::Style::Analysis + attr_reader :ruleset, :subject - def annotations - @annotations ||= @ruleset.analyze(subject) - end + def initialize(ruleset, subject) + @ruleset = ruleset + @subject = subject + end - def fitness - return 1.0 if annotations.length == 0 - @fitness ||= fitness_scores.inject(:+).to_f / fitness_scores.length - end + def messages + annotations.reject(&:adherent?).map(&:message) + end + alias annotation_messages messages - def adherent? - fitness == 1 - end + def annotations + @annotations ||= @ruleset.analyze(subject) + end - private + def fitness + return 1.0 if annotations.empty? + @fitness ||= fitness_scores.inject(:+).to_f / fitness_scores.length + end - def fitness_scores - @fitness_scores ||= annotations.map(&:fitness) - end - end + def adherent? + fitness == 1 + end + + private + + def fitness_scores + @fitness_scores ||= annotations.map(&:fitness) end end