Module: EnigmaEngine::FileHelpers
- Included in:
- Engine
- Defined in:
- lib/enigma_engine/file_helpers.rb
Instance Method Summary collapse
- #create_write_file(txt, file_name, key, date, type = false) ⇒ Object
- #open_file(file_name) ⇒ Object
- #show_msg(new_file, key, date, type = false) ⇒ Object
- #text_to_array(text) ⇒ Object
Instance Method Details
#create_write_file(txt, file_name, key, date, type = false) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/enigma_engine/file_helpers.rb', line 15 def create_write_file(txt, file_name, key, date, type = false) file = File.open(file_name, 'w') file.write(txt) file.close show_msg(file_name, key, date, type) end |
#open_file(file_name) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 |
# File 'lib/enigma_engine/file_helpers.rb', line 3 def open_file(file_name) file = File.open(file_name, 'r') if File.exist? file data = file.read data.gsub(/\n/, ' ') end rescue raise <<NOTIFY "Cannot find file, Run [enigma help] to see help!" NOTIFY end |
#show_msg(new_file, key, date, type = false) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/enigma_engine/file_helpers.rb', line 27 def show_msg(new_file, key, date, type = false) msg = 'Please take note of the key & date in order to decrypt this file' (type) ? msg = yellow(msg) : msg = '' puts <<NOTIFY Created: #{green(new_file)}\nKey: #{red(key)}\nDate: #{blue(date)} #{msg} NOTIFY end |
#text_to_array(text) ⇒ Object
22 23 24 25 |
# File 'lib/enigma_engine/file_helpers.rb', line 22 def text_to_array(text) text = text.split('').map(&:downcase) text.each_slice(4).to_a end |