Sha256: 5cbc390b56363768e77ffa5c88809c97eb5036a537b428a87f4a61277bb74459

Contents?: true

Size: 603 Bytes

Versions: 3

Compression:

Stored size: 603 Bytes

Contents

# 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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
coltrane-2.2.1 lib/coltrane_instruments/guitar/string.rb
coltrane-2.1.5 lib/coltrane_instruments/guitar/string.rb
coltrane-2.1.0 lib/coltrane_instruments/guitar/string.rb