Class: WTFChord::GuitarString

Inherits:
Pitch
  • Object
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

#capoObject (readonly)

Returns the value of attribute capo.



5
6
7
# File 'lib/wtf_chord/guitar_string.rb', line 5

def capo
  @capo
end

#fretObject (readonly)

Returns the value of attribute fret.



5
6
7
# File 'lib/wtf_chord/guitar_string.rb', line 5

def fret
  @fret
end

#originalObject (readonly)

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



58
59
60
61
62
63
64
# File 'lib/wtf_chord/guitar_string.rb', line 58

def <=> other
  return if dead?
  case other
  when Integer      then @fret <=> other
  when GuitarString then @fret <=> other.fret
  end
end

#codeObject



47
48
49
# File 'lib/wtf_chord/guitar_string.rb', line 47

def code
  dead? ? -1 : to_i
end

#deadObject



34
35
36
37
# File 'lib/wtf_chord/guitar_string.rb', line 34

def dead
  @fret = nil
  calculate_note!
end

#dead?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/wtf_chord/guitar_string.rb', line 39

def dead?
  @fret.nil?
end

#distance_to(pitch) ⇒ Object



51
52
53
54
55
56
# File 'lib/wtf_chord/guitar_string.rb', line 51

def distance_to(pitch)
  pos = 0
  opened = dup.open
  pos += 1 while (opened + pos) != pitch
  pos
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

Returns:

  • (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

#openObject



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