Class: ConfigLogic::LogicElement

Inherits:
Object
  • Object
show all
Includes:
Logger
Defined in:
lib/config_logic/logic_element.rb

Direct Known Subclasses

Multiplexer, Overlay

Constant Summary collapse

MIN_INPUTS =
2
NAME =
'logic_element'
STATIC =
true
@@types =
Set.new
@@min_inputs =
MIN_INPUTS

Constants included from ConfigLogic::Logger::Colors

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Logger

#log

Constructor Details

#initialize(params) ⇒ LogicElement

Returns a new instance of LogicElement.



15
16
17
18
19
# File 'lib/config_logic/logic_element.rb', line 15

def initialize(params)
  @name = params[:name] || NAME
  @static = params[:static].nil? ? STATIC : params[:static]
  @inputs = HashWithIndifferentAccess.new
end

Instance Attribute Details

#inputsObject (readonly)

Returns the value of attribute inputs.



10
11
12
# File 'lib/config_logic/logic_element.rb', line 10

def inputs
  @inputs
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/config_logic/logic_element.rb', line 10

def name
  @name
end

Class Method Details

.available_elementsObject



39
40
41
# File 'lib/config_logic/logic_element.rb', line 39

def available_elements
  @@types.map { |t| t.simple_name.downcase }
end

.inherited(child) ⇒ Object



35
36
37
# File 'lib/config_logic/logic_element.rb', line 35

def inherited(child)
  @@types << child
end

.name_to_type(name) ⇒ Object



43
44
45
46
47
# File 'lib/config_logic/logic_element.rb', line 43

def name_to_type(name)
  if available_elements.include?(name)
    ('ConfigLogic::' + name.classify).constantize
  end
end

Instance Method Details

#input_namesObject



25
26
27
# File 'lib/config_logic/logic_element.rb', line 25

def input_names
  @inputs.keys
end

#set_input(input_name, value) ⇒ Object



21
22
23
# File 'lib/config_logic/logic_element.rb', line 21

def set_input(input_name, value)
  @inputs[input_name] = value
end

#static?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/config_logic/logic_element.rb', line 29

def static?
  @static
end