Class: Digiproc::Strategies::CustomCompandingStrategy

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#eqnObject

Returns the value of attribute eqn.



7
8
9
# File 'lib/strategies/companding/custom_companding_strategy.rb', line 7

def eqn
  @eqn
end

#inverseObject

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 expand(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