Module: Readlines::Content
- Included in:
- ReadDuc
- Defined in:
- lib/readlines/readlines/content.rb
Instance Method Summary collapse
- #decrypt_content_now(key, encrypted_file_path) ⇒ Object
- #encrypt_content_now(key) ⇒ Object
- #reverse_content_now ⇒ Object
- #validate_content_now(rules) ⇒ Object
Instance Method Details
#decrypt_content_now(key, encrypted_file_path) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/readlines/readlines/content.rb', line 35 def decrypt_content_now(key, encrypted_file_path) raise Readlines::NotFoundError, "File not found: #{encrypted_file_path}" unless ::File.exist?(encrypted_file_path) encrypted_content = ::File.read(encrypted_file_path) decrypted_content = encrypted_content.chars.map { |char| (char.ord - key).chr }.join decrypted_file_name = encrypted_file_path.sub('.encrypted', '') ::File.write(decrypted_file_name, decrypted_content) decrypted_file_name end |
#encrypt_content_now(key) ⇒ Object
25 26 27 28 29 30 31 32 33 |
# File 'lib/readlines/readlines/content.rb', line 25 def encrypt_content_now(key) raise Readlines::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) content = ::File.read(@file_path) encrypted_content = content.chars.map { |char| (char.ord + key).chr }.join encrypted_file_name = "#{@file_path}.encrypted" ::File.write(encrypted_file_name, encrypted_content) encrypted_file_name end |
#reverse_content_now ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/readlines/readlines/content.rb', line 7 def reverse_content_now raise Readlines::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) content = ::File.readlines(@file_path) reversed_content = content.reverse.join ::File.write(@file_path, reversed_content) reversed_content end |
#validate_content_now(rules) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/readlines/readlines/content.rb', line 16 def validate_content_now(rules) raise Readlines::NotFoundError, "File not found: #{@file_path}" unless ::File.exist?(@file_path) content = ::File.readlines(@file_path) content.all? do |line| rules.all? { |rule| line.match?(rule) } end end |