class Chordproko::Chord

Attributes

content[RW]
key[RW]

Public Class Methods

new(content) click to toggle source
# File lib/chordproko/chord.rb, line 5
def initialize content
  @content = content 
  @chord_list = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
  @chord_indexes = {
    "C" => 0,
    "D" => 2,
    "E" => 4,
    "F" => 5,
    "G" => 7,
    "A" => 9,
    "B" => 11,
  }
end

Public Instance Methods

each(&block) click to toggle source
# File lib/chordproko/chord.rb, line 18
def each(&block)
     [self].each(&block)
end
to_s() click to toggle source
# File lib/chordproko/chord.rb, line 21
def to_s
  "#{transpose_key}"
end
transpose_key() click to toggle source
# File lib/chordproko/chord.rb, line 24
def transpose_key
  return @content.to_s if @key == 0
  chord_value = @chord_indexes[@content.to_s[0]]
  @content.to_s[1..-1].each_char do |mod|
    case mod
    when "#"
      chord_value += 1
    when "b"
      chord_value -= 1
    end
  end
  chord_index = (chord_value + @key)% 12
  res = @chord_list[chord_index]

end