Class: WTFChord::Chord
- Inherits:
-
Object
- Object
- WTFChord::Chord
- Defined in:
- lib/wtf_chord/chord.rb,
lib/wtf_chord/fingerings_generator.rb
Direct Known Subclasses
Constant Summary collapse
- BASS_MATCH =
/(?<=[\\\/])[A-H][b#]?(?=$)/
Instance Attribute Summary collapse
-
#bass ⇒ Object
readonly
Returns the value of attribute bass.
-
#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
- #bass? ⇒ Boolean
- #fingerings(limit = nil) ⇒ Object
-
#initialize(note, name) ⇒ Chord
constructor
A new instance of Chord.
- #inspect ⇒ Object
- #original_bass ⇒ Object
- #third_tone ⇒ Object
Constructor Details
#initialize(note, name) ⇒ Chord
Returns a new instance of Chord.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/wtf_chord/chord.rb', line 10 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!) BASS_MATCH.match(@name) do |m| @bass = WTFChord.note(m[0]).note end end |
Instance Attribute Details
#bass ⇒ Object (readonly)
Returns the value of attribute bass.
8 9 10 |
# File 'lib/wtf_chord/chord.rb', line 8 def bass @bass end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/wtf_chord/chord.rb', line 8 def name @name end |
#notes ⇒ Object (readonly)
Returns the value of attribute notes.
8 9 10 |
# File 'lib/wtf_chord/chord.rb', line 8 def notes @notes end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
8 9 10 |
# File 'lib/wtf_chord/chord.rb', line 8 def pitch @pitch end |
#steps ⇒ Object (readonly)
Returns the value of attribute steps.
8 9 10 |
# File 'lib/wtf_chord/chord.rb', line 8 def steps @steps end |
Instance Method Details
#bass? ⇒ Boolean
29 30 31 |
# File 'lib/wtf_chord/chord.rb', line 29 def bass? !!@bass end |
#fingerings(limit = nil) ⇒ Object
21 22 23 |
# File 'lib/wtf_chord/chord.rb', line 21 def fingerings(limit = nil) FingeringsGenerator.new(self).call[0, limit || 5] end |
#inspect ⇒ Object
37 38 39 |
# File 'lib/wtf_chord/chord.rb', line 37 def inspect "#{name} (#{@notes.map(&:key) * ' - '})" end |
#original_bass ⇒ Object
33 34 35 |
# File 'lib/wtf_chord/chord.rb', line 33 def original_bass @notes[0] end |
#third_tone ⇒ Object
25 26 27 |
# File 'lib/wtf_chord/chord.rb', line 25 def third_tone @third_tone ||= @notes[@steps.size > 3 ? 2 : -1] end |