class SPNet::BlockState
Represent a Block
object using only serializeable objects.
@author James Tunnell
Constants
- ARG_SPECS
Define arg specs to use in processing hashed arguments during initialize.
Attributes
class_sym[R]
params[R]
Public Class Methods
new(args)
click to toggle source
A new instance of NetworkState
. @param [Hash] args Hashed arguments for initialization. See Network::ARG_SPECS
for details of which keys are required.
# File lib/spnet/storage/block_state.rb, line 20 def initialize args hash_make args, BlockState::ARG_SPECS end
Public Instance Methods
make_block(args)
click to toggle source
Produce a Block
object from the current BlockState
object.
# File lib/spnet/storage/block_state.rb, line 25 def make_block args raise ArgumentError, "args does not have :sample_rate key" unless args.has_key?(:sample_rate) klass = find_class(@class_sym) block = klass.new :sample_rate => args[:sample_rate] block.restore_state self return block end
Private Instance Methods
find_class(sym)
click to toggle source
# File lib/spnet/storage/block_state.rb, line 37 def find_class sym s = sym.to_s parts = s.split("::") cur_space = Kernel for i in (0...(parts.count-1)) cur_space = cur_space.const_get(parts[i].to_sym) end return cur_space.const_get parts.last.to_sym end