Class: Omnizip::FilterPipeline
- Inherits:
-
Object
- Object
- Omnizip::FilterPipeline
- Defined in:
- lib/omnizip/filter_pipeline.rb
Overview
Pipeline for chaining multiple filters together.
Filters are applied in sequence during encoding, and in reverse order during decoding. Position tracking is maintained across the entire pipeline.
Instance Attribute Summary collapse
-
#filters ⇒ Object
readonly
Returns the value of attribute filters.
Instance Method Summary collapse
-
#add_filter(filter) ⇒ self
Add a filter to the pipeline.
-
#clear ⇒ void
Clear all filters from the pipeline.
-
#decode(data, position = 0) ⇒ String
Decode (postprocess) data by applying all filters in reverse order.
-
#empty? ⇒ Boolean
Check if pipeline has any filters.
-
#encode(data, position = 0) ⇒ String
Encode (preprocess) data by applying all filters in order.
-
#initialize ⇒ FilterPipeline
constructor
Initialize an empty filter pipeline.
-
#size ⇒ Integer
Get number of filters in pipeline.
Constructor Details
#initialize ⇒ FilterPipeline
Initialize an empty filter pipeline.
29 30 31 32 |
# File 'lib/omnizip/filter_pipeline.rb', line 29 def initialize @filters = [] @position = 0 end |
Instance Attribute Details
#filters ⇒ Object (readonly)
Returns the value of attribute filters.
26 27 28 |
# File 'lib/omnizip/filter_pipeline.rb', line 26 def filters @filters end |
Instance Method Details
#add_filter(filter) ⇒ self
Add a filter to the pipeline.
Filters are applied in the order they are added during encoding, and in reverse order during decoding.
41 42 43 44 |
# File 'lib/omnizip/filter_pipeline.rb', line 41 def add_filter(filter) @filters << filter self end |
#clear ⇒ void
This method returns an undefined value.
Clear all filters from the pipeline.
103 104 105 106 |
# File 'lib/omnizip/filter_pipeline.rb', line 103 def clear @filters.clear @position = 0 end |
#decode(data, position = 0) ⇒ String
Decode (postprocess) data by applying all filters in reverse order.
Filters are applied in reverse order with the same position value to undo the encoding transformation.
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/omnizip/filter_pipeline.rb', line 88 def decode(data, position = 0) return data.dup if @filters.empty? result = data # Apply filters in reverse order @filters.reverse_each do |filter| result = filter.decode(result, position) end result end |
#empty? ⇒ Boolean
Check if pipeline has any filters.
49 50 51 |
# File 'lib/omnizip/filter_pipeline.rb', line 49 def empty? @filters.empty? end |
#encode(data, position = 0) ⇒ String
Encode (preprocess) data by applying all filters in order.
Filters are applied sequentially with the same position value. Position represents the current stream position for address calculations.
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/omnizip/filter_pipeline.rb', line 69 def encode(data, position = 0) return data.dup if @filters.empty? result = data @filters.each do |filter| result = filter.encode(result, position) end result end |
#size ⇒ Integer
Get number of filters in pipeline.
56 57 58 |
# File 'lib/omnizip/filter_pipeline.rb', line 56 def size @filters.size end |