Class: ColtraneInstruments::Guitar::String

Inherits:
Object
  • Object
show all
Defined in:
lib/coltrane_instruments/guitar/string.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pitch, guitar:) ⇒ String

Returns a new instance of String.



8
9
10
11
# File 'lib/coltrane_instruments/guitar/string.rb', line 8

def initialize(pitch, guitar:)
  @guitar = guitar
  @pitch = pitch
end

Instance Attribute Details

#guitarObject (readonly)

Returns the value of attribute guitar.



6
7
8
# File 'lib/coltrane_instruments/guitar/string.rb', line 6

def guitar
  @guitar
end

#pitchObject (readonly)

Returns the value of attribute pitch.



6
7
8
# File 'lib/coltrane_instruments/guitar/string.rb', line 6

def pitch
  @pitch
end

Instance Method Details

#+(fret) ⇒ Object



24
25
26
# File 'lib/coltrane_instruments/guitar/string.rb', line 24

def +(fret)
  pitch + fret
end

#find(pitch_class, possible_frets: (0..guitar.frets).to_a) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/coltrane_instruments/guitar/string.rb', line 13

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