Class: SPNet::ParamInPort

Inherits:
InPort
  • Object
show all
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.

Author:

  • James Tunnell

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

Attributes inherited from InPort

#link, #matching_class

Instance Method Summary collapse

Methods inherited from InPort

#clear_link, #linked?, #set_link

Constructor Details

#initialize(hashed_args = {}) ⇒ ParamInPort

A new instance of ParamInPort.

Parameters:

  • hashed_args (Hash) (defaults to: {})

    Hashed arguments for initialization. See Network::ARG_SPECS for details.



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

#limiterObject (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_valueObject

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