Class: HeadMusic::Style::Analysis

Inherits:
Object
  • Object
show all
Defined in:
lib/head_music/style/analysis.rb

Overview

An analysis of music according to a style guide.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(guide, voice) ⇒ Analysis

Returns a new instance of Analysis.



8
9
10
11
# File 'lib/head_music/style/analysis.rb', line 8

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

Instance Attribute Details

#guideObject (readonly)

Returns the value of attribute guide.



6
7
8
# File 'lib/head_music/style/analysis.rb', line 6

def guide
  @guide
end

#voiceObject (readonly)

Returns the value of attribute voice.



6
7
8
# File 'lib/head_music/style/analysis.rb', line 6

def voice
  @voice
end

Instance Method Details

#adherent?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/head_music/style/analysis.rb', line 28

def adherent?
  fitness == 1
end

#annotationsObject



18
19
20
# File 'lib/head_music/style/analysis.rb', line 18

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

#fitnessObject



22
23
24
25
26
# File 'lib/head_music/style/analysis.rb', line 22

def fitness
  return 1.0 if annotations.empty?

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

#fitness_scoresObject (private)



34
35
36
# File 'lib/head_music/style/analysis.rb', line 34

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

#messagesObject Also known as: annotation_messages



13
14
15
# File 'lib/head_music/style/analysis.rb', line 13

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