Class: MorseMeNicely::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/morse_me_nicely/cli.rb

Instance Method Summary collapse

Instance Method Details

#encodeObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/morse_me_nicely/cli.rb', line 10

def encode
  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
end