Class: Note

Inherits:
Object
  • Object
show all
Defined in:
lib/chord_finder/note.rb

Constant Summary collapse

ACCIDENTALS =
{
  nil => "",
  "#" => "#",
  "!" => "#",
  "b" => "",
  "_" => ""
}
MUTED =
"x".freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, position = nil) ⇒ Note

Returns a new instance of Note.



20
21
22
23
# File 'lib/chord_finder/note.rb', line 20

def initialize(name, position = nil)
  @name = name == MUTED ? name : convert_name(name)
  @position = position
end

Instance Attribute Details

#nameObject (readonly) Also known as: to_s

Returns the value of attribute name.



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

def name
  @name
end

#positionObject (readonly)

Returns the value of attribute position.



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

def position
  @position
end

Class Method Details

.find(name) ⇒ Object



10
11
12
# File 'lib/chord_finder/note.rb', line 10

def self.find(name)
  JOIN_SCALE.find_note(name)
end

Instance Method Details

#+(steps) ⇒ Object



29
30
31
# File 'lib/chord_finder/note.rb', line 29

def +(steps)
  SHARPS_SCALE[position + steps]
end

#==(other_note) ⇒ Object



25
26
27
# File 'lib/chord_finder/note.rb', line 25

def ==(other_note)
  position == other_note.position
end

#muted?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/chord_finder/note.rb', line 33

def muted?
  name == MUTED
end