Class: Digiproc::Strategies::CustomCompandingStrategy
- Inherits:
-
Object
- Object
- Digiproc::Strategies::CustomCompandingStrategy
- Defined in:
- lib/strategies/companding/custom_companding_strategy.rb
Overview
A class which allows a custom companding strategy to be used via a lambda function inputted into the initilizer.
Instance Attribute Summary collapse
-
#eqn ⇒ Object
Returns the value of attribute eqn.
-
#inverse ⇒ Object
Returns the value of attribute inverse.
Instance Method Summary collapse
-
#compress(data) ⇒ Object
use the compression companding lambda (or proc) to compress an array of numerics.
-
#expand(data) ⇒ Object
Use the inverse labda (or proc) to decompress an array of numerics.
-
#initialize(eqn, inverse) ⇒ CustomCompandingStrategy
constructor
initialize wiht a companding equation (via a proc or lambda) as well as the inverse equation.
-
#process(data, fn) ⇒ Object
maps an array (first argument) with a lambda (second argument).
Constructor Details
#initialize(eqn, inverse) ⇒ CustomCompandingStrategy
initialize wiht a companding equation (via a proc or lambda) as well as the inverse equation
10 11 12 |
# File 'lib/strategies/companding/custom_companding_strategy.rb', line 10 def initialize(eqn, inverse) @eqn, @inverse = eqn, inverse end |
Instance Attribute Details
#eqn ⇒ Object
Returns the value of attribute eqn.
7 8 9 |
# File 'lib/strategies/companding/custom_companding_strategy.rb', line 7 def eqn @eqn end |
#inverse ⇒ Object
Returns the value of attribute inverse.
7 8 9 |
# File 'lib/strategies/companding/custom_companding_strategy.rb', line 7 def inverse @inverse end |
Instance Method Details
#compress(data) ⇒ Object
use the compression companding lambda (or proc) to compress an array of numerics
20 21 22 |
# File 'lib/strategies/companding/custom_companding_strategy.rb', line 20 def compress(data) self.process(data, eqn) end |
#expand(data) ⇒ Object
Use the inverse labda (or proc) to decompress an array of numerics
25 26 27 |
# File 'lib/strategies/companding/custom_companding_strategy.rb', line 25 def (data) self.process(data, inverse) end |
#process(data, fn) ⇒ Object
maps an array (first argument) with a lambda (second argument)
15 16 17 |
# File 'lib/strategies/companding/custom_companding_strategy.rb', line 15 def process(data, fn) data.map{ |n| fn.call(n) } end |