Class: ETL::Processor::ZipFileProcessor

Inherits:
Processor show all
Defined in:
lib/etl/processor/zip_file_processor.rb

Overview

Custom processor to zip files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control, configuration) ⇒ ZipFileProcessor

configuration options include:

  • infile - File to zip (required)

  • destination - Zip file name (default: #infile.zip)



13
14
15
16
17
# File 'lib/etl/processor/zip_file_processor.rb', line 13

def initialize(control, configuration)
  path = Pathname.new(configuration[:infile])
  @infile = path.absolute? ? path : Pathname.new(File.dirname(File.expand_path(configuration[:infile]))) + path
  @destination = configuration[:destination] || "#{infile}.zip"
end

Instance Attribute Details

#destinationObject (readonly)

Returns the value of attribute destination



8
9
10
# File 'lib/etl/processor/zip_file_processor.rb', line 8

def destination
  @destination
end

#infileObject (readonly)

Returns the value of attribute infile



7
8
9
# File 'lib/etl/processor/zip_file_processor.rb', line 7

def infile
  @infile
end

Instance Method Details

#processObject



19
20
21
22
23
# File 'lib/etl/processor/zip_file_processor.rb', line 19

def process
  Zip::ZipFile.open(@destination, Zip::ZipFile::CREATE) do |zipfile|
    zipfile.add(@infile.basename, @infile)
  end
end