lib/spnet/ports/signal_in_port.rb in spnet-0.1.4 vs lib/spnet/ports/signal_in_port.rb in spnet-0.1.5

- old
+ new

@@ -1,40 +1,45 @@ -require 'hashmake' -require 'spcore' - module SPNet + +# Recieves signal input for processing in a Block object. +# +# @author James Tunnell class SignalInPort < InPort include Hashmake::HashMakeable - DEFAULT_LIMITS = (-Float::MAX..Float::MAX) + # Define arg specs to use in processing hashed arguments during #initialize. + ARG_SPECS = { + :limiter => arg_spec(:reqd => false, :type => Limiter, :default => ->(){ NoLimiter.new }, :validator => ->(a){ !a.is_a?(EnumLimiter) }), + } - ARG_SPECS = [ - Hashmake::ArgSpec.new(:reqd => false, :key => :limits, :type => Range, :default => DEFAULT_LIMITS) - ] - - attr_reader :limits, :queue + attr_reader :limiter, :queue + # A new instance of SignalInPort. + # @param [Hash] hashed_args Hashed arguments for initialization. See Network::ARG_SPECS + # for details. def initialize hashed_args = {} - hash_make(SignalInPort::ARG_SPECS, hashed_args) + hash_make SignalInPort::ARG_SPECS, hashed_args + @queue = [] - @skip_limiting = (@limits == DEFAULT_LIMITS) - @limiter = SPCore::Limiters.make_range_limiter @limits + @skip_limiting = @limiter.is_a?(NoLimiter) - hashed_args.merge!(:matching_port_class => SignalOutPort) - super(hashed_args) + super(:matching_class => SignalOutPort) end + # Add values to queue. def enqueue_values values unless @skip_limiting for i in 0...values.count - values[i] = @limiter.call(values[i]) + values[i] = @limiter.apply_limit values[i] end end @queue.concat values end + # Remove values to queue. + # @param [Fixnum] count Number of values to remove. def dequeue_values count = @queue.count raise ArgumentError, "count is greater than @queue.count" if count > @queue.count @queue.slice!(0...count) end