Module: Chords::Note

Includes:
Comparable
Defined in:
lib/chords/note.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#intervalObject (readonly)

Returns the value of attribute interval.



8
9
10
# File 'lib/chords/note.rb', line 8

def interval
  @interval
end

#octaveObject (readonly)

Returns the value of attribute octave.



8
9
10
# File 'lib/chords/note.rb', line 8

def octave
  @octave
end

Class Method Details

.create_by_value(value) ⇒ Object



10
11
12
13
14
# File 'lib/chords/note.rb', line 10

def self.create_by_value(value)
  octave = value / 12
  interval = value % 12
  Chords.const_get([NOTES[interval]].flatten.first).new(octave)
end

Instance Method Details

#+(other) ⇒ Object



38
# File 'lib/chords/note.rb', line 38

def +(other); Note.create_by_value(value + other) end

#-(other) ⇒ Object



39
# File 'lib/chords/note.rb', line 39

def -(other); Note.create_by_value(value - other) end

#<=>(other) ⇒ Object



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

def <=>(other)
  if other.respond_to?(:value)
    value <=> other.value
  else
    value <=> other
  end
end

#coerce(other) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/chords/note.rb', line 28

def coerce(other)
  if other.respond_to?(:value)
    [other.value, value]
  else
    [other, value]
  end
end

#titleObject



36
# File 'lib/chords/note.rb', line 36

def title; self.class.title end

#valueObject



16
17
18
# File 'lib/chords/note.rb', line 16

def value
  (@octave * 12) + @interval
end