Class: WTFChord::Chord

Inherits:
Object
  • Object
show all
Defined in:
lib/wtf_chord/chord.rb,
lib/wtf_chord/fingerings_generator.rb

Direct Known Subclasses

FingeringsGenerator

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(note, name) ⇒ Chord



8
9
10
11
12
13
# File 'lib/wtf_chord/chord.rb', line 8

def initialize(note, name)
  @pitch = note.is_a?(Pitch) ? note : WTFChord.note(note)
  @name  = "#{@pitch.key}#{name}".freeze
  @steps = Array(WTFChord.rules[name])
  @notes = @steps.map { |dist| (@pitch + dist).note }.tap(&:uniq!)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#notesObject (readonly)

Returns the value of attribute notes.



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

def notes
  @notes
end

#pitchObject (readonly)

Returns the value of attribute pitch.



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

def pitch
  @pitch
end

#stepsObject (readonly)

Returns the value of attribute steps.



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

def steps
  @steps
end

Instance Method Details

#fingerings(limit = nil) ⇒ Object



19
20
21
22
# File 'lib/wtf_chord/chord.rb', line 19

def fingerings(limit = nil)
  limit ||= 5
  FingeringsGenerator.new(self).call[0, limit]
end

#inspectObject



15
16
17
# File 'lib/wtf_chord/chord.rb', line 15

def inspect
  "#{name} (#{@notes.map(&:key) * ' - '})"
end

#third_toneObject



24
25
26
# File 'lib/wtf_chord/chord.rb', line 24

def third_tone
  @third_tone ||= @notes[@steps.index(7) || -1]
end