Class: OSCAccess::Analog::Output::Range
- Inherits:
-
Object
- Object
- OSCAccess::Analog::Output::Range
- Defined in:
- lib/osc-access/translate.rb
Instance Method Summary collapse
-
#initialize(from, to_range, options = {}) ⇒ Range
constructor
A new instance of Range.
- #process(input, options = {}) ⇒ Object
Constructor Details
#initialize(from, to_range, options = {}) ⇒ Range
Returns a new instance of Range.
60 61 62 63 64 65 |
# File 'lib/osc-access/translate.rb', line 60 def initialize(from, to_range, = {}) @type = [:type] @from = from @to_range = to_range end |
Instance Method Details
#process(input, options = {}) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/osc-access/translate.rb', line 67 def process(input, = {}) to_range_len = (@to_range.last - @to_range.first).abs proportion = to_range_len.to_f / @from.denominator abs_output = proportion.to_f * @from.numerator(input) output = abs_output + @to_range.first type = [:type] || @type float_requested = !type.nil? && type.to_s.downcase == "float" float_requested ? output : output.to_i end |