lib/coltrane/roman_chord.rb in coltrane-1.0.22 vs lib/coltrane/roman_chord.rb in coltrane-1.0.24

- old
+ new

@@ -5,27 +5,33 @@ # It deals with chords in roman notation class RomanChord DIGITS = %w[I II III IV V VI VII].freeze NOTATION_REGEX = %r{ - (?<degree>[ivIV]*) + (?<degree>b?[ivIV]*) (?<quality>.*) }x def initialize(scale, notation) @scale = scale @notation = notation.match(NOTATION_REGEX).named_captures + @notation['quality'] = @notation['quality'] + .gsub('o', 'dim') + .gsub('ø', 'm7b5') end def degree - DIGITS.index(@notation['degree'].upcase) + 1 + d = @notation['degree'] + @flats = d.count('b') + d = d.delete('b') + @degree ||= DIGITS.index(d.upcase) + 1 end def quality_name [ minor_notation, - @notation['quality'].gsub('o', 'dim').gsub('ø', 'm7b5') + @notation['quality'] ].join end def minor_notation return 'm' if !@notation['quality'].match?((/dim|m7b5/)) && !upcase? @@ -44,9 +50,10 @@ q = quality_name ChordQuality.new(name: (q.size.zero? ? 'M' : q)) end def root_note - @scale[@degree] + binding.pry if @scale[degree] - @flats == Note['A#'] + @scale[degree] - @flats end end end