lib/spnet/storage/block_state.rb in spnet-0.1.6 vs lib/spnet/storage/block_state.rb in spnet-0.1.7
- old
+ new
@@ -7,14 +7,14 @@
include Hashmake::HashMakeable
# Define arg specs to use in processing hashed arguments during #initialize.
ARG_SPECS = {
:class_sym => arg_spec(:reqd => true, :type => Symbol),
- :params => arg_spec_hash(:reqd => false, :type => Object)
+ :params => arg_spec_hash(:reqd => false, :type => Object),
}
- attr_reader :class_sym, :hashed_args, :params
+ attr_reader :class_sym, :params
# A new instance of NetworkState.
# @param [Hash] args Hashed arguments for initialization. See Network::ARG_SPECS
# for details of which keys are required.
def initialize args
@@ -23,19 +23,28 @@
# Produce a Block object from the current BlockState object.
def make_block args
raise ArgumentError, "args does not have :sample_rate key" unless args.has_key?(:sample_rate)
- klass = Kernel.const_get(@class_sym)
+ klass = find_class(@class_sym)
block = klass.new :sample_rate => args[:sample_rate]
+ block.restore_state self
- @params.each do |port_name,value|
- if block.in_ports.has_key?(port_name)
- port = block.in_ports[port_name]
- port.set_value value
- end
+ return block
+ end
+
+ private
+
+ 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 block
+ return cur_space.const_get parts.last.to_sym
end
end
end