Sha256: 60a25c50ce44e4b343a175f5732db800eab8094bd090d4d7e0b0391bf2ab751b

Contents?: true

Size: 753 Bytes

Versions: 2

Compression:

Stored size: 753 Bytes

Contents

module HeadMusic
  module Style
    class Analysis
      attr_reader :ruleset, :subject, :annotations

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

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

      def annotations
        @annotations ||= @ruleset.analyze(subject)
      end

      def fitness
        return 1.0 if annotations.length == 0
        @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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
head_music-0.17.0 lib/head_music/style/analysis.rb
head_music-0.16.2 lib/head_music/style/analysis.rb