class CW_Parser

args to cw_parser: text | code, file, filepath, play code sounds (implement sound later)

Attributes

filepath[RW]
mode[RW]
morse_code[R]
sound[RW]

Public Class Methods

new(mode=:text,filepath="",sound="no") click to toggle source
# File lib/cw_parser.rb, line 18
def initialize(mode=:text,filepath="",sound="no")
       @mode = mode
       @filepath = filepath
       @sound = sound

       @morse_code = { 
     "A" => '.-', "B" => '-...', "C" => '-.-.', "D" => '-..', "E" => '.', "F" => '..-.', "G" => '--.',
     "H" => '....', "I" => '..', "J" => '.---', "K" => '-.-', "L" => '.-..', "M" => '--',
     "N" => '-.', "O" => '---', "P" => '.--.', "Q" => '--.-', "R" => '.-.', "S" => '...',
     "T" => '-', "U" => '..-', "V" => '...-', "W" => '.--', "X" => '-..-', "Y" => '-.--',
     "Z" => '--..', "1" => '.----', "2" => '..---', "3" => '...--', "4" => '....-', "5" => '.....',
     "6" => '-....', "7" => '--...', "8" => '---..', "9" => '----.', "0" => '-----', " " => ' ',
   }

end

Public Instance Methods

translate_file(path="") click to toggle source
# File lib/cw_parser.rb, line 34
def translate_file(path="")
 if true == File.exist?(path)
  puts "path: #{path}" 
  puts "mode= #{@mode}"
  ftranslate = File.read(path)
  ftranslate.gsub!(/\n/, " ")
 else 
  puts "#{path} does not exist"
 end

 if @mode == :text
  puts ftranslate.inspect
  parse_text(ftranslate)
 else 
  puts ftranslate.inspect
  parse_code(ftranslate)
 end
end