Class: Pondize::Convert
- Inherits:
-
Object
- Object
- Pondize::Convert
- 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) ⇒ Convert
constructor
A new instance of Convert.
- #notes_to_change ⇒ Object
- #pondize(chars = nil) ⇒ Object
Constructor Details
#initialize(key_signature, chars) ⇒ Convert
Returns a new instance of Convert.
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
46 47 48 49 50 51 52 53 54 |
# File 'lib/pondize/runner.rb', line 46 def change_to if @key_signature > 0 return 's' end if @key_signature < 0 return 'f' end '' end |
#notes_to_change ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/pondize/runner.rb', line 56 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(chars = nil) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/pondize/runner.rb', line 29 def pondize chars = nil @chars = chars || @chars @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(/ -(\d)/, '-\1') .gsub('< <', '<<') .gsub('> >', '>>') .gsub(' .', '.') .gsub('l', 'f') .strip end |