Class: Omnizip::Commands::CompressCommand
- Inherits:
-
Object
- Object
- Omnizip::Commands::CompressCommand
- Defined in:
- lib/omnizip/commands/compress_command.rb
Overview
Command to compress files using specified algorithm.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CompressCommand
constructor
Initialize compress command with options.
-
#run(input_file, output_file) ⇒ void
Execute the compress command.
Constructor Details
#initialize(options = {}) ⇒ CompressCommand
Initialize compress command with options.
28 29 30 |
# File 'lib/omnizip/commands/compress_command.rb', line 28 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/omnizip/commands/compress_command.rb', line 23 def @options end |
Instance Method Details
#run(input_file, output_file) ⇒ void
This method returns an undefined value.
Execute the compress command.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/omnizip/commands/compress_command.rb', line 37 def run(input_file, output_file) validate_inputs(input_file, output_file) algorithm_name = [:algorithm] || "lzma" level = [:level] || 5 verbose = [:verbose] || false CliOutputFormatter.verbose_puts( "Compressing #{input_file} to #{output_file}...", verbose, ) CliOutputFormatter.verbose_puts( "Algorithm: #{algorithm_name}, Level: #{level}", verbose, ) start_time = Time.now compress_file(input_file, output_file, algorithm_name, level) elapsed = Time.now - start_time input_size = File.size(input_file) output_size = File.size(output_file) if verbose puts "" puts CliOutputFormatter.format_compression_stats( input_size, output_size, elapsed, ) else puts "Compressed: #{input_file} -> #{output_file}" end end |