Class: SpreadsheetEncrypt::Encryptor

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheet_encrypt/encryptor.rb

Overview

Encrypts spreadsheet files with an Office open password.

Constant Summary collapse

SUPPORTED_EXTENSIONS =
%w[.xls .xlsx].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_path, password, output_path) ⇒ Encryptor

Returns a new instance of Encryptor.



17
18
19
20
21
# File 'lib/spreadsheet_encrypt/encryptor.rb', line 17

def initialize(input_path, password, output_path)
  @input_path = input_path.to_s
  @password = password.to_s
  @output_path = output_path.to_s
end

Class Method Details

.encrypt(input_path, password, output_path) ⇒ Object



13
14
15
# File 'lib/spreadsheet_encrypt/encryptor.rb', line 13

def self.encrypt(input_path, password, output_path)
  new(input_path, password, output_path).encrypt
end

Instance Method Details

#encrypt ⇒ String

Returns actual output path written.

Returns:

  • (String) —

    actual output path written



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/spreadsheet_encrypt/encryptor.rb', line 24

def encrypt
  validate!
  ensure_output_directory!

  case extension
  when ".xlsx"
    encrypt_xlsx(@input_path, @output_path)
  when ".xls"
    encrypt_xls
  end
end