class Chord

Attributes

name[R]

Public Class Methods

new(name) click to toggle source
# File lib/chord_finder/chord.rb, line 3
def initialize(name)
  @name = name
  validate!
end

Public Instance Methods

==(other_chord) click to toggle source
# File lib/chord_finder/chord.rb, line 12
def ==(other_chord)
  notes == other_chord.notes
end
fifth() click to toggle source
# File lib/chord_finder/chord.rb, line 24
def fifth
  notes[2]
end
first() click to toggle source
# File lib/chord_finder/chord.rb, line 16
def first
  notes[0]
end
notes() click to toggle source
# File lib/chord_finder/chord.rb, line 8
def notes
  @notes ||= find_notes
end
third() click to toggle source
# File lib/chord_finder/chord.rb, line 20
def third
  notes[1]
end
to_s() click to toggle source
# File lib/chord_finder/chord.rb, line 28
def to_s
  notes.map(&:to_s).join(" ")
end

Private Instance Methods

find_notes() click to toggle source
# File lib/chord_finder/chord.rb, line 33
def find_notes
  note_name, suffix = parse_name
  root = Note.find(note_name)
  steps = CHORD_RULES[suffix]
  steps.map { |dist| root + dist }
end
parse_name() click to toggle source
# File lib/chord_finder/chord.rb, line 44
def parse_name
  match = name.match(/^[a-gA-G][#!b_]?/)
  [match[0], match.post_match]
end
valid?() click to toggle source
# File lib/chord_finder/chord.rb, line 49
def valid?
  !!(name =~ /^[a-gA-G][#!b_]?[a-zA-z]*7*$/)
end
validate!() click to toggle source
# File lib/chord_finder/chord.rb, line 40
def validate!
  raise ArgumentError.new("This chord is not currently supported") unless valid?
end