Class: Circuits::Component::Base
- Inherits:
-
Object
- Object
- Circuits::Component::Base
- Defined in:
- lib/circuits/component/base.rb
Overview
Base class to extend
Instance Attribute Summary collapse
-
#inputs ⇒ Object
readonly
the inputs of this component.
-
#outputs ⇒ Object
readonly
the outputs of this component.
Instance Method Summary collapse
-
#[](port) ⇒ Input, Output
Gets the teminal assigned to the port.
-
#initialize(opts = {}) ⇒ Base
constructor
Creates the Component with inputs and outputs.
-
#tock ⇒ Object
Sets all the outputs expose what was set in #tick.
Constructor Details
#initialize(opts = {}) ⇒ Base
Creates the Component with inputs and outputs
16 17 18 19 20 21 22 |
# File 'lib/circuits/component/base.rb', line 16 def initialize(opts = {}) input_count = opts[:input_count] || default_input_count output_count = opts[:output_count] || default_output_count @inputs = input_count.times.collect { Circuits::Terminal::Input.new } @outputs = output_count.times.collect { Circuits::Terminal::Output.new } @port_mappings = opts[:port_mappings] || default_port_mappings end |
Instance Attribute Details
#inputs ⇒ Object (readonly)
the inputs of this component
25 26 27 |
# File 'lib/circuits/component/base.rb', line 25 def inputs @inputs end |
#outputs ⇒ Object (readonly)
the outputs of this component
28 29 30 |
# File 'lib/circuits/component/base.rb', line 28 def outputs @outputs end |
Instance Method Details
#[](port) ⇒ Input, Output
Gets the teminal assigned to the port
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/circuits/component/base.rb', line 38 def [](port) port_mapping = port_mappings[port] port_number = port_mapping[:number] case port_mapping[:type] when :input inputs[port_number] when :output outputs[port_number] end end |
#tock ⇒ Object
Sets all the outputs expose what was set in #tick
31 32 33 |
# File 'lib/circuits/component/base.rb', line 31 def tock outputs.each(&:tock) end |