Sha256: 404f36633de882707bb648a15d505a2d619184c81771717b2f90304c0b9e9d32
Contents?: true
Size: 646 Bytes
Versions: 3
Compression:
Stored size: 646 Bytes
Contents
module Coltrane class RomanChord DIGITS = { 'I' => 1, 'V' => 5, } 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: is_major? ? 'M' : 'm') end def is_major? @roman_numeral[0] =~ /[[:upper]]/ end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
coltrane-1.0.11 | lib/coltrane/roman_chord.rb |
coltrane-1.0.1 | lib/coltrane/roman_chord.rb |
coltrane-1.0.0 | lib/coltrane/roman_chord.rb |