Class: Omnizip::Converter::ConversionStrategy

Inherits:
Object
  • Object
show all
Defined in:
lib/omnizip/converter/conversion_strategy.rb

Overview

Base class for archive format conversion strategies

Direct Known Subclasses

SevenZipToZipStrategy, ZipToSevenZipStrategy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_path, target_path, options) ⇒ ConversionStrategy

Initialize conversion strategy

Parameters:

  • source_path (String)

    Source archive path

  • target_path (String)

    Target archive path

  • options (ConversionOptions)

    Conversion options



13
14
15
16
17
18
# File 'lib/omnizip/converter/conversion_strategy.rb', line 13

def initialize(source_path, target_path, options)
  @source_path = source_path
  @target_path = target_path
  @options = options
  @warnings = []
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/omnizip/converter/conversion_strategy.rb', line 7

def options
  @options
end

#source_pathObject (readonly)

Returns the value of attribute source_path.



7
8
9
# File 'lib/omnizip/converter/conversion_strategy.rb', line 7

def source_path
  @source_path
end

#target_pathObject (readonly)

Returns the value of attribute target_path.



7
8
9
# File 'lib/omnizip/converter/conversion_strategy.rb', line 7

def target_path
  @target_path
end

Class Method Details

.can_convert?(_source, _target) ⇒ Boolean

Check if this strategy can handle the conversion

Parameters:

  • source (String)

    Source file path

  • target (String)

    Target file path

Returns:

  • (Boolean)

    True if can handle



45
46
47
# File 'lib/omnizip/converter/conversion_strategy.rb', line 45

def self.can_convert?(_source, _target)
  false
end

Instance Method Details

#convertConversionResult

Perform the conversion

Returns:

  • (ConversionResult)

    Conversion result

Raises:

  • (NotImplementedError)

    Subclasses must implement



23
24
25
# File 'lib/omnizip/converter/conversion_strategy.rb', line 23

def convert
  raise NotImplementedError, "#{self.class} must implement #convert"
end

#source_formatSymbol

Get source format

Returns:

  • (Symbol)

    Source format

Raises:

  • (NotImplementedError)

    Subclasses must implement



30
31
32
# File 'lib/omnizip/converter/conversion_strategy.rb', line 30

def source_format
  raise NotImplementedError, "#{self.class} must implement #source_format"
end

#target_formatSymbol

Get target format

Returns:

  • (Symbol)

    Target format

Raises:

  • (NotImplementedError)

    Subclasses must implement



37
38
39
# File 'lib/omnizip/converter/conversion_strategy.rb', line 37

def target_format
  raise NotImplementedError, "#{self.class} must implement #target_format"
end