Class: SPNet::Block
- Inherits:
-
Object
- Object
- SPNet::Block
- Includes:
- Hashmake::HashMakeable
- Defined in:
- lib/spnet/core/block.rb
Overview
Base class for encapsulating processing functionality. Connects to other blocks via input and output ports.
Constant Summary collapse
- ARG_SPECS =
Define ArgSpec’s to use in processing hashed arguments during #initialize.
{ :sample_rate => arg_spec(:reqd => true, :type => Numeric, :validator => ->(a){ a > 0 }), :algorithm => arg_spec(:reqd => true, :type => Proc, :validator => ->(p){ p.arity == 1 }), :in_ports => arg_spec_hash(:reqd => false, :type => InPort), :out_ports => arg_spec_hash(:reqd => false, :type => OutPort), }
Instance Attribute Summary collapse
-
#in_ports ⇒ Object
readonly
Returns the value of attribute in_ports.
-
#out_ports ⇒ Object
readonly
Returns the value of attribute out_ports.
-
#sample_rate ⇒ Object
readonly
Returns the value of attribute sample_rate.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Block
constructor
A new instance of Block.
- #restore_state(state) ⇒ Object
-
#save_state ⇒ BlockState
Produces a BlockState object based on this Block object.
-
#step(count) ⇒ Object
Execute the block algorithm.
Constructor Details
Instance Attribute Details
#in_ports ⇒ Object (readonly)
Returns the value of attribute in_ports.
10 11 12 |
# File 'lib/spnet/core/block.rb', line 10 def in_ports @in_ports end |
#out_ports ⇒ Object (readonly)
Returns the value of attribute out_ports.
10 11 12 |
# File 'lib/spnet/core/block.rb', line 10 def out_ports @out_ports end |
#sample_rate ⇒ Object (readonly)
Returns the value of attribute sample_rate.
10 11 12 |
# File 'lib/spnet/core/block.rb', line 10 def sample_rate @sample_rate end |
Instance Method Details
#restore_state(state) ⇒ Object
49 50 51 52 53 54 55 |
# 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 ⇒ BlockState
Produces a BlockState object based on this Block object.
36 37 38 39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
Execute the block algorithm.
30 31 32 |
# File 'lib/spnet/core/block.rb', line 30 def step count @algorithm.call count end |