Sha256: cb9fb09cf58a55692ff626b510a245ecb2f97d6b85ea18c830ee942c56c6faa6
Contents?: true
Size: 721 Bytes
Versions: 3
Compression:
Stored size: 721 Bytes
Contents
# frozen_string_literal: true module Coltrane # It deals with chords in roman notation class RomanChord DIGITS = { 'I' => 1, 'V' => 5 }.freeze def initialize(scale, roman_numeral) @scale = scale @roman_numeral = roman_numeral end def to_chord Chord.new root_note: root_note, quality: quality end def root_note @scale[degree] end def degree @roman_numeral.split('').reduce(0) do |memo, r| memo + (DIGITS[r] || 0) + (DIGITS[r.swapcase] || 0) end end def quality ChordQuality.new(name: major? ? 'M' : 'm') end def major? @roman_numeral[0] =~ /[[:upper]]/ end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
coltrane-1.0.21 | lib/coltrane/roman_chord.rb |
coltrane-1.0.20 | lib/coltrane/roman_chord.rb |
coltrane-1.0.2 | lib/coltrane/roman_chord.rb |