Class: WTFChord::GuitarString
- Inherits:
-
Pitch
- Object
- Pitch
- WTFChord::GuitarString
show all
- Defined in:
- lib/wtf_chord/guitar_string.rb
Instance Attribute Summary collapse
Attributes inherited from Pitch
#note, #octave
Instance Method Summary
collapse
Methods inherited from Pitch
#-, #==, #chord, #move, #to_i, #to_s, #to_str
Constructor Details
#initialize(note, capo = 0) ⇒ GuitarString
Returns a new instance of GuitarString.
7
8
9
10
11
12
|
# File 'lib/wtf_chord/guitar_string.rb', line 7
def initialize(note, capo = 0)
@original = WTFChord.note(note)
@fret = nil
@capo = capo
super(@original + capo)
end
|
Instance Attribute Details
#capo ⇒ Object
Returns the value of attribute capo.
5
6
7
|
# File 'lib/wtf_chord/guitar_string.rb', line 5
def capo
@capo
end
|
#fret ⇒ Object
Returns the value of attribute fret.
5
6
7
|
# File 'lib/wtf_chord/guitar_string.rb', line 5
def fret
@fret
end
|
#original ⇒ Object
Returns the value of attribute original.
5
6
7
|
# File 'lib/wtf_chord/guitar_string.rb', line 5
def original
@original
end
|
Instance Method Details
#<=>(other) ⇒ Object
51
52
53
54
55
56
57
|
# File 'lib/wtf_chord/guitar_string.rb', line 51
def <=> other
return if dead?
case other
when Integer then @fret <=> other
when GuitarString then @fret <=> other.fret
end
end
|
#code ⇒ Object
47
48
49
|
# File 'lib/wtf_chord/guitar_string.rb', line 47
def code
dead? ? -1 : to_i
end
|
#dead ⇒ Object
34
35
36
37
|
# File 'lib/wtf_chord/guitar_string.rb', line 34
def dead
@fret = nil
calculate_note!
end
|
#dead? ⇒ Boolean
39
40
41
|
# File 'lib/wtf_chord/guitar_string.rb', line 39
def dead?
@fret.nil?
end
|
#hold_on(fret) ⇒ Object
24
25
26
27
|
# File 'lib/wtf_chord/guitar_string.rb', line 24
def hold_on(fret)
@fret = fret
calculate_note!
end
|
#holded? ⇒ Boolean
43
44
45
|
# File 'lib/wtf_chord/guitar_string.rb', line 43
def holded?
!dead? && @fret > 0
end
|
#initialize_dup(other) ⇒ Object
14
15
16
17
|
# File 'lib/wtf_chord/guitar_string.rb', line 14
def initialize_dup(other)
super
__setobj__(@original.dup)
end
|
#open ⇒ Object
29
30
31
32
|
# File 'lib/wtf_chord/guitar_string.rb', line 29
def open
@fret = 0
calculate_note!
end
|
#set_capo(capo) ⇒ Object
19
20
21
22
|
# File 'lib/wtf_chord/guitar_string.rb', line 19
def set_capo(capo)
@capo = capo
calculate_note!
end
|