Class: FileComposer::Documents::Zip

Inherits:
Base
  • Object
show all
Defined in:
lib/file_composer/documents/zip.rb

Overview

Can compress documents together into a zip file.

Instance Attribute Summary collapse

Attributes inherited from Base

#filename

Instance Method Summary collapse

Constructor Details

#initialize(filename:, blueprint: {}) ⇒ Zip

Returns a new instance of Zip.



18
19
20
21
22
# File 'lib/file_composer/documents/zip.rb', line 18

def initialize(filename:, blueprint: {})
  super(filename: filename)

  @blueprint = Blueprint.make(blueprint)
end

Instance Attribute Details

#blueprintObject (readonly)

Returns the value of attribute blueprint.



16
17
18
# File 'lib/file_composer/documents/zip.rb', line 16

def blueprint
  @blueprint
end

Instance Method Details

#write!(temp_root = '', store = Stores::Null.new) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/file_composer/documents/zip.rb', line 24

def write!(temp_root = '', store = Stores::Null.new)
  results               = blueprint.write!(temp_root)
  write_time_in_seconds = results.sum(&:time_in_seconds)
  physical_filename     = nil

  zip_time_in_seconds = Benchmark.measure do
    physical_filename = zip!(temp_root, results)
  end.real

  total_time_in_seconds = write_time_in_seconds + zip_time_in_seconds

  cleanup(results)

  final_filename = store.move!(physical_filename)
  file_result = FileResult.new(filename, final_filename)

  Result.new(file_result, total_time_in_seconds)
end