Class: Coltrane::Theory::ScaleSet

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/coltrane/theory/scale_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*scales, searched_notes: nil) ⇒ ScaleSet

Returns a new instance of ScaleSet.



9
10
11
12
# File 'lib/coltrane/theory/scale_set.rb', line 9

def initialize(*scales, searched_notes: nil)
  @scales = scales.uniq
  @searched_notes = searched_notes
end

Instance Attribute Details

#scalesObject

Returns the value of attribute scales.



7
8
9
# File 'lib/coltrane/theory/scale_set.rb', line 7

def scales
  @scales
end

#searched_notesObject

Returns the value of attribute searched_notes.



7
8
9
# File 'lib/coltrane/theory/scale_set.rb', line 7

def searched_notes
  @searched_notes
end

Instance Method Details

#full_namesObject



35
36
37
# File 'lib/coltrane/theory/scale_set.rb', line 35

def full_names
  map(&:full_name)
end

#namesObject



31
32
33
# File 'lib/coltrane/theory/scale_set.rb', line 31

def names
  map(&:name)
end

#resultsObject



20
21
22
23
24
25
26
27
28
29
# File 'lib/coltrane/theory/scale_set.rb', line 20

def results
  raise 'No searched notes were provided' unless searched_notes
  @table ||=
    scales.each_with_object({}) do |scale, the_table|
      the_table[scale.name] ||= {}
      the_table[scale.name][scale.tone.pitch_class.name] = (
        scale.notes & searched_notes
      )
    end
end

#strict_scalesObject



14
15
16
17
18
# File 'lib/coltrane/theory/scale_set.rb', line 14

def strict_scales
  @strict_scales ||= scales.select do |scale|
    (scale.notes & searched_notes).size == searched_notes.size
  end
end