Class: Stringed::Instrument

Inherits:
Object
  • Object
show all
Defined in:
lib/stringed/instrument.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strings, options = {}) ⇒ Instrument

Returns a new instance of Instrument.



7
8
9
10
# File 'lib/stringed/instrument.rb', line 7

def initialize(strings,options={})
  @strings = strings.map{ |string| InstrumentString.new(string.to_s, options)}
  @fret_count = options.fetch(:fret_count,14)
end

Instance Attribute Details

#fret_countObject

Returns the value of attribute fret_count.



5
6
7
# File 'lib/stringed/instrument.rb', line 5

def fret_count
  @fret_count
end

#stringsObject

Returns the value of attribute strings.



5
6
7
# File 'lib/stringed/instrument.rb', line 5

def strings
  @strings
end

Instance Method Details

#find(note) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/stringed/instrument.rb', line 12

def find(note)
  matches = []
  strings.each do |string|
    matches << string.find(note)
  end
  matches
end

#find_chord(chord) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/stringed/instrument.rb', line 20

def find_chord(chord)
  matches = []
  strings.each do |string|
    matches << string.find_chord(chord)
  end
  matches
end

#in_range?(fret_no) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/stringed/instrument.rb', line 28

def in_range?(fret_no)
  fret_no >= 0 and fret_no <= fret_count
end

#to(format, options = {}) ⇒ Object



32
33
34
35
36
37
# File 'lib/stringed/instrument.rb', line 32

def to(format,options={})
  require "stringed/formatters"
  if format == :ascii then
    Formatters::ASCIIInstrument.new(self,options)
  end
end