Class: SPNet::ParamInPort
- Includes:
- Hashmake::HashMakeable
- Defined in:
- lib/spnet/ports/param_in_port.rb
Overview
Provides a means to get/set a parameter value in a Block object.
Constant Summary collapse
- ARG_SPECS =
Define arg specs to use in processing hashed arguments during #initialize.
{ :limiter => arg_spec(:reqd => false, :type => Limiter, :default => ->(){ NoLimiter.new } ), :get_value_handler => arg_spec(:reqd => true, :type => Proc, :validator => ->(p){ p.arity == 0 }), :set_value_handler => arg_spec(:reqd => true, :type => Proc, :validator => ->(p){ p.arity == 1 }) }
Instance Attribute Summary collapse
-
#limiter ⇒ Object
readonly
Returns the value of attribute limiter.
Attributes inherited from InPort
Instance Method Summary collapse
-
#get_value ⇒ Object
Get the parameter’s current value.
-
#initialize(hashed_args = {}) ⇒ ParamInPort
constructor
A new instance of ParamInPort.
-
#set_value(value) ⇒ Object
Set the parameter to the given value.
Methods inherited from InPort
#clear_link, #linked?, #set_link
Constructor Details
#initialize(hashed_args = {}) ⇒ ParamInPort
A new instance of ParamInPort.
22 23 24 25 26 27 |
# File 'lib/spnet/ports/param_in_port.rb', line 22 def initialize hashed_args = {} hash_make hashed_args, ParamInPort::ARG_SPECS @skip_limiting = @limiter.is_a?(NoLimiter) super(:matching_class => ParamOutPort) end |
Instance Attribute Details
#limiter ⇒ Object (readonly)
Returns the value of attribute limiter.
17 18 19 |
# File 'lib/spnet/ports/param_in_port.rb', line 17 def limiter @limiter end |
Instance Method Details
#get_value ⇒ Object
Get the parameter’s current value.
38 39 40 |
# File 'lib/spnet/ports/param_in_port.rb', line 38 def get_value @get_value_handler.call end |
#set_value(value) ⇒ Object
Set the parameter to the given value.
30 31 32 33 34 35 |
# File 'lib/spnet/ports/param_in_port.rb', line 30 def set_value value unless @skip_limiting value = @limiter.apply_limit value, get_value end @set_value_handler.call value end |