Class: Omnizip::Algorithm
- Inherits:
-
Object
- Object
- Omnizip::Algorithm
- Defined in:
- lib/omnizip/algorithm.rb
Overview
Abstract base class for compression algorithms.
All compression algorithms should inherit from this class and implement the required methods. Algorithms are automatically registered with the AlgorithmRegistry when defined.
Direct Known Subclasses
Omnizip::Algorithms::BZip2, Omnizip::Algorithms::Deflate, Omnizip::Algorithms::Deflate64, Omnizip::Algorithms::LZMA, Omnizip::Algorithms::LZMA2, Omnizip::Algorithms::PPMd7, Omnizip::Algorithms::PPMdBase, Omnizip::Algorithms::SevenZipLZMA2, Omnizip::Algorithms::XZLZMA2, Omnizip::Algorithms::Zstandard
Instance Attribute Summary collapse
-
#filter ⇒ Object
readonly
Returns the value of attribute filter.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
-
.inherited(subclass) ⇒ void
Automatically register algorithm when inherited.
-
.metadata ⇒ Models::AlgorithmMetadata
Get metadata about this algorithm.
Instance Method Summary collapse
-
#compress(input, output) ⇒ void
Compress data from input to output.
-
#decompress(input, output) ⇒ void
Decompress data from input to output.
-
#initialize(options = {}) ⇒ Algorithm
constructor
Initialize algorithm with options.
-
#with_filter(filter) ⇒ self
Set a preprocessing filter for this algorithm.
Constructor Details
#initialize(options = {}) ⇒ Algorithm
Initialize algorithm with options.
31 32 33 34 |
# File 'lib/omnizip/algorithm.rb', line 31 def initialize( = {}) @options = @filter = nil end |
Instance Attribute Details
#filter ⇒ Object (readonly)
Returns the value of attribute filter.
26 27 28 |
# File 'lib/omnizip/algorithm.rb', line 26 def filter @filter end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/omnizip/algorithm.rb', line 26 def @options end |
Class Method Details
.inherited(subclass) ⇒ void
This method returns an undefined value.
Automatically register algorithm when inherited.
This hook is called whenever a class inherits from Algorithm, automatically registering it with the AlgorithmRegistry.
92 93 94 95 96 97 98 99 100 101 |
# File 'lib/omnizip/algorithm.rb', line 92 def inherited(subclass) super # Register algorithm when metadata is defined subclass.define_singleton_method(:register_algorithm) do = subclass. AlgorithmRegistry.register(.name.to_sym, subclass) rescue NotImplementedError # Metadata not yet defined, will be registered manually end end |
.metadata ⇒ Models::AlgorithmMetadata
Get metadata about this algorithm.
80 81 82 83 |
# File 'lib/omnizip/algorithm.rb', line 80 def raise NotImplementedError, "#{self} must implement .metadata" end |
Instance Method Details
#compress(input, output) ⇒ void
This method returns an undefined value.
Compress data from input to output.
If a filter is set, data is filtered before compression.
57 58 59 60 |
# File 'lib/omnizip/algorithm.rb', line 57 def compress(input, output) raise NotImplementedError, "#{self.class} must implement #compress" end |
#decompress(input, output) ⇒ void
This method returns an undefined value.
Decompress data from input to output.
If a filter is set, data is unfiltered after decompression.
70 71 72 73 |
# File 'lib/omnizip/algorithm.rb', line 70 def decompress(input, output) raise NotImplementedError, "#{self.class} must implement #decompress" end |
#with_filter(filter) ⇒ self
Set a preprocessing filter for this algorithm.
The filter will be applied before compression and reversed after decompression. Returns self for method chaining.
44 45 46 47 |
# File 'lib/omnizip/algorithm.rb', line 44 def with_filter(filter) @filter = filter self end |