Class: Pondize::Cv
- Inherits:
-
Object
- Object
- Pondize::Cv
- Defined in:
- lib/pondize/runner.rb
Constant Summary collapse
- CIRCLE =
"fcgdaeb"- ACCIDENTALS =
['l', 'n', 's']
- OCTAVES =
[",", "'"]
Instance Method Summary collapse
- #change_to ⇒ Object
-
#initialize(key_signature, chars) ⇒ Cv
constructor
A new instance of Cv.
- #notes_to_change ⇒ Object
- #pondize ⇒ Object
Constructor Details
#initialize(key_signature, chars) ⇒ Cv
24 25 26 27 |
# File 'lib/pondize/runner.rb', line 24 def initialize key_signature, chars @key_signature = key_signature @chars = chars end |
Instance Method Details
#change_to ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/pondize/runner.rb', line 43 def change_to if @key_signature > 0 return 's' end if @key_signature < 0 return 's' end '' end |
#notes_to_change ⇒ Object
53 54 55 56 57 58 59 60 61 |
# File 'lib/pondize/runner.rb', line 53 def notes_to_change if @key_signature > 0 return CIRCLE[0...@key_signature] end if @key_signature < 0 return CIRCLE[@key_signature..-1] end [] end |
#pondize ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/pondize/runner.rb', line 29 def pondize @chars.each_char .map .with_index { |char, index| (notes_to_change.include?(char) && !ACCIDENTALS.include?(@chars[index + 1]) ) ? "#{char}#{change_to}" : char } .map.with_index { |char, index| (ACCIDENTALS + OCTAVES).include?(@chars[index + 1]) ? char : "#{char} " } .join('') .gsub('n', '') .gsub(/ (\d)/, '\1') .gsub('< <', '<<') .gsub('> >', '>>') .gsub(' .', '.') .gsub('l', 'f') end |