Class: Chords::Chord

Inherits:
Object
  • Object
show all
Defined in:
lib/chords/chord.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#notesObject (readonly)

Returns the value of attribute notes.



6
7
8
# File 'lib/chords/chord.rb', line 6

def notes
  @notes
end

#rootObject

Returns the value of attribute root.



7
8
9
# File 'lib/chords/chord.rb', line 7

def root
  @root
end

Instance Method Details

#add11Object



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

#add9Object



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_inversionObject



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_inversionObject



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

#seventhObject



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

#sixthObject



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

#titleObject



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