Class: ConfigLogic::Multiplexer

Inherits:
LogicElement show all
Defined in:
lib/config_logic/multiplexer.rb

Constant Summary

Constants inherited from LogicElement

LogicElement::MIN_INPUTS, LogicElement::NAME, LogicElement::STATIC

Constants included from Logger::Colors

Logger::Colors::BLUE, Logger::Colors::GREEN, Logger::Colors::RED, Logger::Colors::RESET, Logger::Colors::YELLOW

Instance Attribute Summary collapse

Attributes inherited from LogicElement

#inputs, #name

Instance Method Summary collapse

Methods inherited from LogicElement

available_elements, inherited, #input_names, name_to_type, #set_input, #static?

Methods included from Logger

#log

Constructor Details

#initialize(params) ⇒ Multiplexer

Returns a new instance of Multiplexer.



5
6
7
8
9
10
# File 'lib/config_logic/multiplexer.rb', line 5

def initialize(params)
  super
  @multiplexer = params[:inputs]
  @inputs = HashWithIndifferentAccess.new(@multiplexer.values.to_hash)
  @selector = params[:selector]
end

Instance Attribute Details

#selectorObject (readonly)

Returns the value of attribute selector.



3
4
5
# File 'lib/config_logic/multiplexer.rb', line 3

def selector
  @selector
end

Instance Method Details

#outputObject



12
13
14
15
16
17
18
19
20
# File 'lib/config_logic/multiplexer.rb', line 12

def output
  return unless inputs_valid?
  case @selector
  when Proc
    @inputs[@multiplexer[@selector.call]]
  else
    @inputs[@multiplexer[@selector]]
  end
end