Class: WTFChord::Chord
- Inherits:
-
Object
- Object
- WTFChord::Chord
- Defined in:
- lib/wtf_chord/chord.rb,
lib/wtf_chord/fingerings_generator.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#notes ⇒ Object
readonly
Returns the value of attribute notes.
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
-
#steps ⇒ Object
readonly
Returns the value of attribute steps.
Instance Method Summary collapse
- #fingerings(limit = nil) ⇒ Object
-
#initialize(note, name) ⇒ Chord
constructor
A new instance of Chord.
- #inspect ⇒ Object
- #third_tone ⇒ Object
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
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/wtf_chord/chord.rb', line 6 def name @name end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
6 7 8 |
# File 'lib/wtf_chord/chord.rb', line 6 def notes @notes end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
6 7 8 |
# File 'lib/wtf_chord/chord.rb', line 6 def pitch @pitch end |
#steps ⇒ Object (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 |
#inspect ⇒ Object
15 16 17 |
# File 'lib/wtf_chord/chord.rb', line 15 def inspect "#{name} (#{@notes.map(&:key) * ' - '})" end |
#third_tone ⇒ Object
24 25 26 |
# File 'lib/wtf_chord/chord.rb', line 24 def third_tone @third_tone ||= @notes[@steps.index(7) || -1] end |