Class: WTFChord::InstrumentPitch

Inherits:
Pitch
  • Object
show all
Defined in:
lib/wtf_chord/instrument_pitch.rb

Direct Known Subclasses

GuitarString, PianoKey

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) ⇒ InstrumentPitch

Returns a new instance of InstrumentPitch.



9
10
11
12
# File 'lib/wtf_chord/instrument_pitch.rb', line 9

def initialize(note)
  @original = WTFChord.note(note)
  super(init_pitch)
end

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



7
8
9
# File 'lib/wtf_chord/instrument_pitch.rb', line 7

def interval
  @interval
end

#originalObject (readonly)

Returns the value of attribute original.



7
8
9
# File 'lib/wtf_chord/instrument_pitch.rb', line 7

def original
  @original
end

Instance Method Details

#<=>(other) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/wtf_chord/instrument_pitch.rb', line 44

def <=> other
  case other
  when Integer
    to_i <=> other
  when InstrumentPitch
    to_i <=> other.to_i
  end
end

#codeObject



40
41
42
# File 'lib/wtf_chord/instrument_pitch.rb', line 40

def code
  to_i
end

#deadObject



23
24
# File 'lib/wtf_chord/instrument_pitch.rb', line 23

def dead
end

#dead?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/wtf_chord/instrument_pitch.rb', line 26

def dead?
  raise NotImplementedError
end

#distance_to(pitch) ⇒ Object



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

def distance_to(pitch)
  pos = 0
  pos += 1 while (original + pos) != pitch
  pos
end

#holded?Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


30
31
32
# File 'lib/wtf_chord/instrument_pitch.rb', line 30

def holded?
  raise NotImplementedError
end

#init_pitchObject



14
15
16
# File 'lib/wtf_chord/instrument_pitch.rb', line 14

def init_pitch
  @original
end

#initialize_dup(other) ⇒ Object



18
19
20
21
# File 'lib/wtf_chord/instrument_pitch.rb', line 18

def initialize_dup(other)
  super
  __setobj__(@original.dup)
end