class MorseMeNicely::CLI
Public Instance Methods
encode()
click to toggle source
# File lib/morse_me_nicely/cli.rb, line 10 def encode begin if options[:input_file] input_text = File.read(options[:input_file]) else input_text = ask(set_color("Write the message:", Thor::Shell::Color::GREEN)) end encoded_text = MorseMeNicely::Processor::encode(input_text, options[:without_obfuscation]) if options[:output_file] output_file = File.new(options[:output_file], "w+") output_file << encoded_text output_file.close say("Encoded message has been saved to selected file.", Thor::Shell::Color::GREEN) else say("Encoded message:", Thor::Shell::Color::GREEN) say(encoded_text) end rescue MorseMeNicely::InvalidInputError => e say_error(e) rescue Errno::ENOENT say_error("Input file '#{options[:input_file]}' does not exist") rescue Errno::EACCES say_error("You don't have permissions to read file '#{options[:input_file] || options[:output_file]}'") end end
Private Instance Methods
say_error(msg)
click to toggle source
# File lib/morse_me_nicely/cli.rb, line 38 def say_error(msg) say("Error: #{msg}", Thor::Shell::Color::RED) end