class SPNet::Block
Base class for encapsulating processing functionality. Connects to other blocks via input and output ports.
@author James Tunnell
Constants
- ARG_SPECS
Define ArgSpec's to use in processing hashed arguments during initialize.
Attributes
in_ports[R]
out_ports[R]
sample_rate[R]
Public Class Methods
new(args = {})
click to toggle source
A new instance of Block
. @param [Hash] args Hashed arguments for initialization. See Block::ARG_SPECS
for details of which keys are required.
# File lib/spnet/core/block.rb, line 23 def initialize args = {} hash_make args, Block::ARG_SPECS @initial_params = collect_params end
Public Instance Methods
restore_state(state)
click to toggle source
# File lib/spnet/core/block.rb, line 49 def restore_state state state.params.each do |port_name,value| if @in_ports.has_key?(port_name) @in_ports[port_name].set_value value end end end
save_state()
click to toggle source
Produces a BlockState
object based on this Block
object. @return [BlockState]
# File lib/spnet/core/block.rb, line 36 def save_state params = collect_params # discard the params that are the same as the initial port params params.keys.each do |key| if params[key] == @initial_params[key] params.delete key end end BlockState.new(:class_sym => self.class.to_s.to_sym, :params => params) end
step(count)
click to toggle source
Execute the block algorithm. @param [Fixnum] count The number of steps to execute. Passed on to the algorithm Proc.
# File lib/spnet/core/block.rb, line 30 def step count @algorithm.call count end
Private Instance Methods
collect_params()
click to toggle source
# File lib/spnet/core/block.rb, line 59 def collect_params params = {} @in_ports.each do |name, port| if port.is_a?(ParamInPort) params[name] = port.get_value end end return params end