Class: Omnizip::Converter::SevenZipToZipStrategy
- Inherits:
-
ConversionStrategy
- Object
- ConversionStrategy
- Omnizip::Converter::SevenZipToZipStrategy
- Defined in:
- lib/omnizip/converter/seven_zip_to_zip_strategy.rb
Overview
Convert 7-Zip archives to ZIP format
Instance Attribute Summary
Attributes inherited from ConversionStrategy
#options, #source_path, #target_path
Class Method Summary collapse
-
.can_convert?(source, target) ⇒ Boolean
Check if can convert.
Instance Method Summary collapse
-
#convert ⇒ ConversionResult
Perform 7z to ZIP conversion.
-
#source_format ⇒ Symbol
Get source format.
-
#target_format ⇒ Symbol
Get target format.
Methods inherited from ConversionStrategy
Constructor Details
This class inherits a constructor from Omnizip::Converter::ConversionStrategy
Class Method Details
.can_convert?(source, target) ⇒ Boolean
Check if can convert
49 50 51 |
# File 'lib/omnizip/converter/seven_zip_to_zip_strategy.rb', line 49 def self.can_convert?(source, target) source.end_with?(".7z") && target.end_with?(".zip") end |
Instance Method Details
#convert ⇒ ConversionResult
Perform 7z to ZIP conversion
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/omnizip/converter/seven_zip_to_zip_strategy.rb', line 11 def convert start_time = Time.now reader = Omnizip::Formats::SevenZip::Reader.new(source_path) reader.open entry_count = reader.list_files.size Dir.mktmpdir("omnizip_convert") do |tmp| reader.extract_all(tmp) writer = Omnizip::Formats::Zip::Writer.new(target_path) Dir.glob(File.join(tmp, "**", "*")).each do |path| next if File.directory?(path) writer.add_file(path, path.delete_prefix("#{tmp}/")) end writer.write end create_result(start_time, entry_count) end |
#source_format ⇒ Symbol
Get source format
35 36 37 |
# File 'lib/omnizip/converter/seven_zip_to_zip_strategy.rb', line 35 def source_format :seven_zip end |
#target_format ⇒ Symbol
Get target format
41 42 43 |
# File 'lib/omnizip/converter/seven_zip_to_zip_strategy.rb', line 41 def target_format :zip end |