Module: Circuits::Component
- Defined in:
- lib/circuits/component.rb,
lib/circuits/component/or.rb,
lib/circuits/component/and.rb,
lib/circuits/component/nor.rb,
lib/circuits/component/not.rb,
lib/circuits/component/xor.rb,
lib/circuits/component/nand.rb,
lib/circuits/component/xnor.rb,
lib/circuits/component/sr_nor.rb,
lib/circuits/component/sr_nand.rb
Overview
A component has a set of inputs an outputs. Every ‘tick` a componnent computes its outputs, but the componnent will wait for the `tock` before the componnent updates its own outputs
Defined Under Namespace
Classes: And, Nand, Nor, Not, Or, SrNand, SrNor, Xnor, Xor
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.
-
#[]=(port, terminal) ⇒ Input, Output
Assigns to an input or output.
-
#initialize(opts = {}) ⇒ Object
Creates the Component with inputs and outputs.
-
#tick ⇒ Object
Does the internal computation and sets the outputs.
-
#tock ⇒ Object
Sets all the outputs expose what was set in #tick.
Instance Attribute Details
#inputs ⇒ Object (readonly)
the inputs of this component
59 60 61 |
# File 'lib/circuits/component.rb', line 59 def inputs @inputs end |
#outputs ⇒ Object (readonly)
the outputs of this component
62 63 64 |
# File 'lib/circuits/component.rb', line 62 def outputs @outputs end |
Instance Method Details
#[](port) ⇒ Input, Output
Gets the teminal assigned to the port
34 35 36 37 38 39 40 41 42 |
# File 'lib/circuits/component.rb', line 34 def [](port) p = @port_mappings[port] case p[:type] when :input @inputs[p[:number]] when :output @outputs[p[:number]] end end |
#[]=(port, terminal) ⇒ Input, Output
Assigns to an input or output
48 49 50 51 52 53 54 55 56 |
# File 'lib/circuits/component.rb', line 48 def []=(port, terminal) p = @port_mappings[port] case p[:type] when :input @inputs[p[:number]] = terminal when :output @outputs[p[:number]] = terminal end end |
#initialize(opts = {}) ⇒ Object
Creates the Component with inputs and outputs
13 14 15 16 17 18 19 |
# File 'lib/circuits/component.rb', line 13 def initialize(opts = {}) set_defaults create_inputs opts create_outputs opts create_port_mappings setup end |
#tick ⇒ Object
Does the internal computation and sets the outputs
22 23 24 |
# File 'lib/circuits/component.rb', line 22 def tick fail NotImplementedError end |
#tock ⇒ Object
Sets all the outputs expose what was set in #tick
27 28 29 |
# File 'lib/circuits/component.rb', line 27 def tock outputs.each(&:tock) end |