Class: EnigmaEncrypto::Encrypt
- Inherits:
-
Object
- Object
- EnigmaEncrypto::Encrypt
- Defined in:
- lib/enigma_encrypto/encrypt.rb
Instance Method Summary collapse
- #action ⇒ Object
- #check_command_args ⇒ Object
- #encrypt ⇒ Object
- #get_command_args ⇒ Object
-
#initialize ⇒ Encrypt
constructor
A new instance of Encrypt.
Constructor Details
#initialize ⇒ Encrypt
Returns a new instance of Encrypt.
7 8 9 10 11 |
# File 'lib/enigma_encrypto/encrypt.rb', line 7 def initialize @file_handler = FileHandler.new @rotator = Rotator.new @rotation_num_gen = RotationNumGen.new end |
Instance Method Details
#action ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/enigma_encrypto/encrypt.rb', line 37 def action exit if !get_command_args exit if !check_command_args encrypt key = @rotation_num_gen.showkey date = @rotation_num_gen.today_date puts "Created #{@encrypted} with the key #{key} and date #{date}" true end |
#check_command_args ⇒ Object
23 24 25 26 27 28 |
# File 'lib/enigma_encrypto/encrypt.rb', line 23 def check_command_args operation = @file_handler.check_file_useability(, @encrypted) return false if operation == false || operation == "c" File.truncate(@encrypted, 0) if operation == "w" true end |
#encrypt ⇒ Object
30 31 32 33 34 35 |
# File 'lib/enigma_encrypto/encrypt.rb', line 30 def encrypt @opened_msg = @file_handler.read() length = @opened_msg.size (length) @opened_msg.close end |
#get_command_args ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/enigma_encrypto/encrypt.rb', line 13 def get_command_args if ARGV.length != 2 puts "Oooops!\nIncorrect number of arguments supplied.\nTry again." false else = ARGV[0] @encrypted = ARGV[1] end end |