Class: WTFChord::Fretboard
- Inherits:
-
Object
- Object
- WTFChord::Fretboard
- Defined in:
- lib/wtf_chord/fretboard.rb
Direct Known Subclasses
Constant Summary collapse
- DEAD =
"×"
Instance Attribute Summary collapse
-
#capo ⇒ Object
readonly
Returns the value of attribute capo.
-
#strings ⇒ Object
readonly
Returns the value of attribute strings.
Instance Method Summary collapse
- #[](idx) ⇒ Object
- #fingers ⇒ Object
-
#initialize(*strings) ⇒ Fretboard
constructor
A new instance of Fretboard.
- #set_capo(capo = 0) ⇒ Object
- #to_s ⇒ Object (also: #inspect)
- #with_capo(capo) ⇒ Object
Constructor Details
#initialize(*strings) ⇒ Fretboard
Returns a new instance of Fretboard.
11 12 13 14 |
# File 'lib/wtf_chord/fretboard.rb', line 11 def initialize(*strings) @capo = 0 @strings = strings.map { |string| GuitarString.new(string, @capo) } end |
Instance Attribute Details
#capo ⇒ Object (readonly)
Returns the value of attribute capo.
9 10 11 |
# File 'lib/wtf_chord/fretboard.rb', line 9 def capo @capo end |
#strings ⇒ Object (readonly)
Returns the value of attribute strings.
9 10 11 |
# File 'lib/wtf_chord/fretboard.rb', line 9 def strings @strings end |
Instance Method Details
#[](idx) ⇒ Object
16 17 18 19 20 |
# File 'lib/wtf_chord/fretboard.rb', line 16 def [] idx case idx when 1..@strings.length then @strings[-idx] end end |
#fingers ⇒ Object
36 37 38 |
# File 'lib/wtf_chord/fretboard.rb', line 36 def fingers @strings.map { |string| string.dead? ? DEAD : string.fret } end |
#set_capo(capo = 0) ⇒ Object
22 23 24 25 26 |
# File 'lib/wtf_chord/fretboard.rb', line 22 def set_capo(capo = 0) @capo = capo @strings.each { |string| string.set_capo(@capo) } self end |
#to_s ⇒ Object Also known as: inspect
40 41 42 |
# File 'lib/wtf_chord/fretboard.rb', line 40 def to_s "[ #{fingers * " "} ]" end |
#with_capo(capo) ⇒ Object
28 29 30 31 32 33 34 |
# File 'lib/wtf_chord/fretboard.rb', line 28 def with_capo(capo) capo_was = @capo set_capo(capo) yield ensure set_capo(capo_was) end |