Class: Coltrane::Representation::Guitar::String
- Inherits:
-
Object
- Object
- Coltrane::Representation::Guitar::String
- Defined in:
- lib/coltrane/representation/guitar/string.rb
Instance Attribute Summary collapse
-
#guitar ⇒ Object
readonly
Returns the value of attribute guitar.
-
#pitch ⇒ Object
readonly
Returns the value of attribute pitch.
Instance Method Summary collapse
- #+(fret) ⇒ Object
- #find(pitch_class, possible_frets: (0..guitar.frets).to_a) ⇒ Object
-
#initialize(pitch, guitar:) ⇒ String
constructor
A new instance of String.
Constructor Details
#initialize(pitch, guitar:) ⇒ String
Returns a new instance of String.
9 10 11 12 |
# File 'lib/coltrane/representation/guitar/string.rb', line 9 def initialize(pitch, guitar:) @guitar = guitar @pitch = pitch end |
Instance Attribute Details
#guitar ⇒ Object (readonly)
Returns the value of attribute guitar.
7 8 9 |
# File 'lib/coltrane/representation/guitar/string.rb', line 7 def guitar @guitar end |
#pitch ⇒ Object (readonly)
Returns the value of attribute pitch.
7 8 9 |
# File 'lib/coltrane/representation/guitar/string.rb', line 7 def pitch @pitch end |
Instance Method Details
#+(fret) ⇒ Object
25 26 27 |
# File 'lib/coltrane/representation/guitar/string.rb', line 25 def +(fret) pitch + fret end |
#find(pitch_class, possible_frets: (0..guitar.frets).to_a) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/coltrane/representation/guitar/string.rb', line 14 def find(pitch_class, possible_frets: (0..guitar.frets).to_a) output = [] n = 0 loop do f = (pitch_class.integer - pitch.integer) % 12 + 12 * n possible_frets.include?(f) ? output << Note.new(self, f) : break n += 1 end output end |