Class: CompareCompressors::Compressor

Inherits:
Object
  • Object
show all
Defined in:
lib/compare_compressors/compressor.rb

Overview

Base class for compressors. Subclasses provide compressor-specific configuration and logic.

Instance Method Summary collapse

Instance Method Details

#compression_commandArray<String>

This method is abstract.

Returns command to run the compressor.

Returns:

  • (Array<String>)

    command to run the compressor

Raises:

  • (NotImplementedError)


77
78
79
# File 'lib/compare_compressors/compressor.rb', line 77

def compression_command
  raise NotImplementedError
end

#decompression_commandArray<String>

This method is abstract.

Returns command to run the compressor in decompress mode.

Returns:

  • (Array<String>)

    command to run the compressor in decompress mode

Raises:

  • (NotImplementedError)


85
86
87
# File 'lib/compare_compressors/compressor.rb', line 85

def decompression_command
  raise NotImplementedError
end

#display_nameString

Returns display name (need not be safe to intern as a symbol).

Returns:

  • (String)

    display name (need not be safe to intern as a symbol)



69
70
71
# File 'lib/compare_compressors/compressor.rb', line 69

def display_name
  name
end

#evaluate(target, work_target, level) ⇒ Result

Run the compressor at the given level on the given target and measure its running time and memory usage.

Parameters:

  • target (String)

    original pathname of the target (read only)

  • work_target (String)

    temporary path of the target (read/write)

  • level (Numeric)

    the compression level

Returns:



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/compare_compressors/compressor.rb', line 21

def evaluate(target, work_target, level)
  compression_times = time(compression_command(work_target, level))
  size = output_size(work_target)
  remove_if_exists(work_target)

  decompression_times = time(decompression_command(work_target))
  remove_if_exists(output_name(work_target))

  Result.new(
    target, name, level, *compression_times, size, *decompression_times
  )
end

#extensionString

This method is abstract.

Returns extension added to the compressed file.

Returns:

  • (String)

    extension added to the compressed file

Raises:

  • (NotImplementedError)


46
47
48
# File 'lib/compare_compressors/compressor.rb', line 46

def extension
  raise NotImplementedError
end

#levelsArray<Integer>

This method is abstract.

Returns the levels supported by the compressor.

Returns:

  • (Array<Integer>)

    the levels supported by the compressor

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/compare_compressors/compressor.rb', line 54

def levels
  raise NotImplementedError
end

#nameString

This method is abstract.

Returns name that can be a ruby symbol.

Returns:

  • (String)

    name that can be a ruby symbol

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/compare_compressors/compressor.rb', line 38

def name
  raise NotImplementedError
end

#versionString?

This method is abstract.

Returns version string (for information only).

Returns:

  • (String?)

    version string (for information only)



62
63
64
# File 'lib/compare_compressors/compressor.rb', line 62

def version
  nil
end