Class: Compression::Pipeline

Inherits:
Strategy show all
Defined in:
lib/compression/pipeline.rb

Constant Summary

Constants inherited from Strategy

Strategy::DestinationFileExistsError, Strategy::ExtractFailed

Instance Method Summary collapse

Methods inherited from Strategy

#can_handle?

Constructor Details

#initialize(strategies) ⇒ Pipeline

Returns a new instance of Pipeline.



5
6
7
# File 'lib/compression/pipeline.rb', line 5

def initialize(strategies)
  @strategies = strategies
end

Instance Method Details

#compress(path, target_name) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/compression/pipeline.rb', line 13

def compress(path, target_name)
  current_target = target_name
  @strategies.reduce("") do |compressed_path, strategy|
    compressed_path = strategy.compress(path, current_target)
    current_target = compressed_path.split("/").last

    compressed_path
  end
end

#decompress(dest_path, compressed_file_path, max_size) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/compression/pipeline.rb', line 23

def decompress(dest_path, compressed_file_path, max_size)
  @strategies
    .reverse
    .reduce(compressed_file_path) do |to_decompress, strategy|
      next_compressed_file = strategy.decompress(dest_path, to_decompress, max_size)
      FileUtils.rm_rf(to_decompress)
      next_compressed_file
    end
end

#extensionObject



9
10
11
# File 'lib/compression/pipeline.rb', line 9

def extension
  @strategies.reduce("") { |ext, strategy| ext += strategy.extension }
end