Class: Oscillo::NumSignal
Overview
A signal that works on numeric values.
Instance Method Summary collapse
-
#delta ⇒ Signal
The new signal gives the difference between the previous value and the current value of the signal.
-
#div(signal) ⇒ Signal
(also: #/)
The new signal is the division of the original signal and the given signal.
-
#initialize(&block) ⇒ NumSignal
constructor
Creates a new Signal with an optional initial value, signals to follow, and block.
-
#minus(signal) ⇒ Signal
(also: #-)
The new signal is the difference of the original signal and the given signal.
-
#mod(signal) ⇒ Signal
(also: #%)
The new signal is the modulus of the original signal and the given signal.
-
#plus(signal) ⇒ Signal
(also: #+)
The new signal is the sum of the original signal and the given signal.
-
#pow(signal) ⇒ Signal
(also: #**)
The new signal is the original signal raised to the power of the given signal.
-
#product ⇒ Signal
The new signal gives the running product of all values of the original signal.
-
#sum ⇒ Signal
The new signal gives the running total of all values of the original signal.
-
#times(signal) ⇒ Signal
(also: #*)
The new signal is the product of the original signal and the given signal.
Methods inherited from Signal
#abort, #change, #dont_follow, #drop_repeats, #follow, #on_change, #sample_on, #source, #to_i, #to_s, #update, #value
Methods included from Enumerable
#all?, #any?, #collect, #count, #each, #find_all, #inject, #reject, #zip
Constructor Details
#initialize(*signals) {|*signals, self| ... } ⇒ NumSignal #initialize(start_value, *signals) {|*signals, self| ... } ⇒ NumSignal
Creates a new Signal with an optional initial value, signals to follow, and block. The block converts the values from any signals that this one follows to the value of this signal. If no block is given, the value will be an array of all the values of the signals that it follows (or if it is just following one signal, the value of that signal).
Defaults to 0 instead of nil.
6 7 8 |
# File 'lib/oscillo/num_signal.rb', line 6 def initialize(*, &block) @value = 0; super end |
Instance Method Details
#delta ⇒ Signal
The new signal gives the difference between the previous value and the current value of the signal.
22 23 24 25 26 27 |
# File 'lib/oscillo/num_signal.rb', line 22 def delta prev = self.val self.class.new(self) do |v, s| v - prev.tap { prev = v } end end |
#div(signal) ⇒ Signal Also known as: /
The new signal is the division of the original signal and the given signal.
71 72 73 |
# File 'lib/oscillo/num_signal.rb', line 71 def div(signal) self.class.new(self, signal) { |a, b| a / b } end |
#minus(signal) ⇒ Signal Also known as: -
The new signal is the difference of the original signal and the given signal.
51 52 53 |
# File 'lib/oscillo/num_signal.rb', line 51 def minus(signal) self.class.new(self, signal) { |a, b| a - b } end |
#mod(signal) ⇒ Signal Also known as: %
The new signal is the modulus of the original signal and the given signal.
81 82 83 |
# File 'lib/oscillo/num_signal.rb', line 81 def mod(signal) self.class.new(self, signal) { |a, b| a % b } end |
#plus(signal) ⇒ Signal Also known as: +
The new signal is the sum of the original signal and the given signal.
41 42 43 |
# File 'lib/oscillo/num_signal.rb', line 41 def plus(signal) self.class.new(self, signal) { |a, b| a + b} end |
#pow(signal) ⇒ Signal Also known as: **
The new signal is the original signal raised to the power of the given signal.
91 92 93 |
# File 'lib/oscillo/num_signal.rb', line 91 def pow(signal) self.class.new(self, signal) { |a, b| a ** b } end |
#product ⇒ Signal
The new signal gives the running product of all values of the original signal.
33 34 35 |
# File 'lib/oscillo/num_signal.rb', line 33 def product self.inject(:*) end |
#sum ⇒ Signal
The new signal gives the running total of all values of the original signal.
14 15 16 |
# File 'lib/oscillo/num_signal.rb', line 14 def sum self.inject(:+) end |
#times(signal) ⇒ Signal Also known as: *
The new signal is the product of the original signal and the given signal.
61 62 63 |
# File 'lib/oscillo/num_signal.rb', line 61 def times(signal) self.class.new(self, signal) { |a, b| a * b } end |