lib/coltrane_instruments/guitar/string.rb in coltrane-2.0.0 vs lib/coltrane_instruments/guitar/string.rb in coltrane-2.1.0

- old
+ new

@@ -1,8 +1,29 @@ # frozen_string_literal: true module ColtraneInstruments module Guitar class String + attr_reader :pitch, :guitar + + def initialize(pitch, guitar:) + @guitar = guitar + @pitch = pitch + end + + 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 + + def +(fret) + pitch + fret + end end end end