Module: Omnizip::Converter
- Defined in:
- lib/omnizip/converter.rb,
lib/omnizip/converter/conversion_registry.rb,
lib/omnizip/converter/conversion_strategy.rb,
lib/omnizip/converter/seven_zip_to_zip_strategy.rb,
lib/omnizip/converter/zip_to_seven_zip_strategy.rb
Overview
Archive format conversion module Provides conversion between different archive formats
Defined Under Namespace
Classes: ConversionRegistry, ConversionStrategy, SevenZipToZipStrategy, ZipToSevenZipStrategy
Class Method Summary collapse
-
.batch_convert(sources, target_format: :seven_zip, **options) {|result| ... } ⇒ Array<ConversionResult>
Batch convert multiple archives.
-
.convert(source_path, target_path, **options) ⇒ ConversionResult
Convert archive from one format to another.
-
.convert_with_options(source_path, target_path, options) ⇒ ConversionResult
Convert with explicit options object.
-
.strategies ⇒ Array<Class>
Get available conversion strategies.
-
.supported?(source_path, target_path) ⇒ Boolean
Check if conversion is supported.
Class Method Details
.batch_convert(sources, target_format: :seven_zip, **options) {|result| ... } ⇒ Array<ConversionResult>
Batch convert multiple archives
78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/omnizip/converter.rb', line 78 def batch_convert(sources, target_format: :seven_zip, **, &block) results = [] sources.each do |source| target = generate_target_path(source, target_format) result = convert(source, target, target_format: target_format, **) results << result yield(result) if block end results end |
.convert(source_path, target_path, **options) ⇒ ConversionResult
Convert archive from one format to another
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/omnizip/converter.rb', line 21 def convert(source_path, target_path, **) # Find appropriate strategy first strategy_class = ConversionRegistry.find_strategy(source_path, target_path) unless strategy_class raise ArgumentError, "No conversion strategy available for " \ "#{source_path} -> #{target_path}" end # Then validate input files unless File.exist?(source_path) raise Errno::ENOENT, "Source file not found: #{source_path}" end # Create options object opts = .is_a?(Models::ConversionOptions) ? : (**) opts.validate # Perform conversion strategy = strategy_class.new(source_path, target_path, opts) result = strategy.convert # Delete source if requested File.delete(source_path) if opts.delete_source && File.exist?(source_path) result end |
.convert_with_options(source_path, target_path, options) ⇒ ConversionResult
Convert with explicit options object
54 55 56 |
# File 'lib/omnizip/converter.rb', line 54 def (source_path, target_path, ) convert(source_path, target_path, ) end |
.strategies ⇒ Array<Class>
Get available conversion strategies
68 69 70 |
# File 'lib/omnizip/converter.rb', line 68 def strategies ConversionRegistry.strategies end |
.supported?(source_path, target_path) ⇒ Boolean
Check if conversion is supported
62 63 64 |
# File 'lib/omnizip/converter.rb', line 62 def supported?(source_path, target_path) ConversionRegistry.supported?(source_path, target_path) end |