Class: Chordproko::Chord
- Inherits:
-
Object
- Object
- Chordproko::Chord
- Defined in:
- lib/chordproko/chord.rb
Instance Attribute Summary collapse
-
#content ⇒ Object
Returns the value of attribute content.
-
#key ⇒ Object
Returns the value of attribute key.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(content) ⇒ Chord
constructor
A new instance of Chord.
- #to_s ⇒ Object
- #transpose_key ⇒ Object
Constructor Details
#initialize(content) ⇒ Chord
Returns a new instance of Chord.
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# 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 |
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
4 5 6 |
# File 'lib/chordproko/chord.rb', line 4 def content @content end |
#key ⇒ Object
Returns the value of attribute key.
4 5 6 |
# File 'lib/chordproko/chord.rb', line 4 def key @key end |
Instance Method Details
#each(&block) ⇒ Object
18 19 20 |
# File 'lib/chordproko/chord.rb', line 18 def each(&block) [self].each(&block) end |
#to_s ⇒ Object
21 22 23 |
# File 'lib/chordproko/chord.rb', line 21 def to_s "#{transpose_key}" end |
#transpose_key ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# 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 |