Class: Chords::Chord
- Inherits:
-
Object
- Object
- Chords::Chord
- Defined in:
- lib/chords/chord.rb
Instance Attribute Summary collapse
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #add11 ⇒ Object
- #add9 ⇒ Object
- #bass(note) ⇒ Object
- #first_inversion ⇒ Object
-
#initialize(title_parts, *notes) ⇒ Chord
constructor
A new instance of Chord.
- #second_inversion ⇒ Object
- #seventh ⇒ Object
- #sixth ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(title_parts, *notes) ⇒ Chord
Returns a new instance of Chord.
9 10 11 12 13 |
# File 'lib/chords/chord.rb', line 9 def initialize(title_parts, *notes) @title_parts = title_parts @notes = notes.flatten @root = @notes.first end |
Instance Attribute Details
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
6 7 8 |
# File 'lib/chords/chord.rb', line 6 def notes @notes end |
#root ⇒ Object
Returns the value of attribute root.
7 8 9 |
# File 'lib/chords/chord.rb', line 7 def root @root end |
Instance Method Details
#add11 ⇒ Object
49 50 51 52 53 |
# File 'lib/chords/chord.rb', line 49 def add11 chord = Chord.new(@title_parts.dup + ['add11'], @notes + [@root + 17]) chord.root = @root chord end |
#add9 ⇒ Object
43 44 45 46 47 |
# File 'lib/chords/chord.rb', line 43 def add9 chord = Chord.new(@title_parts.dup + ['add9'], @notes + [@root + 14]) chord.root = @root chord end |
#bass(note) ⇒ Object
55 56 57 58 59 |
# File 'lib/chords/chord.rb', line 55 def bass(note) chord = Chord.new(@title_parts.dup + ["(bass #{note.title})"], [note] + @notes) chord.root = @root chord end |
#first_inversion ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/chords/chord.rb', line 15 def first_inversion raise "Not enough notes for inversion" if notes.size < 3 inversion = Chord.new(@title_parts.dup + ['1st inv.'], @notes[1], @notes[2], @root, *@notes[3..-1]) inversion.root = @root inversion end |
#second_inversion ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/chords/chord.rb', line 23 def second_inversion raise "Not enough notes for inversion" if notes.size < 3 inversion = Chord.new(@title_parts.dup + ['2nd inv.'], @notes[2], @root, @notes[1], *@notes[3..-1]) inversion.root = @root inversion end |
#seventh ⇒ Object
37 38 39 40 41 |
# File 'lib/chords/chord.rb', line 37 def seventh chord = Chord.new(@title_parts.dup + ['7th'], @notes + [@root + 10]) chord.root = @root chord end |
#sixth ⇒ Object
31 32 33 34 35 |
# File 'lib/chords/chord.rb', line 31 def sixth chord = Chord.new(@title_parts.dup + ['6th'], @notes + [@root + 9]) chord.root = @root chord end |
#title ⇒ Object
61 62 63 64 65 |
# File 'lib/chords/chord.rb', line 61 def title ret = @root.title ret += " #{@title_parts.join(' ')}" unless @title_parts.empty? ret end |