Class: TruthTable
- Inherits:
-
Object
- Object
- TruthTable
- Defined in:
- lib/logic_analyzer/truth_table.rb
Instance Attribute Summary collapse
-
#iterations ⇒ Object
Returns the value of attribute iterations.
-
#table ⇒ Object
Returns the value of attribute table.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #generate_table ⇒ Object
-
#initialize(variables) ⇒ TruthTable
constructor
A new instance of TruthTable.
- #truth_value_of(variable, row) ⇒ Object
Constructor Details
#initialize(variables) ⇒ TruthTable
Returns a new instance of TruthTable.
4 5 6 7 8 |
# File 'lib/logic_analyzer/truth_table.rb', line 4 def initialize(variables) @variables = variables @iterations = 2 ** variables.size @table = [] end |
Instance Attribute Details
#iterations ⇒ Object
Returns the value of attribute iterations.
2 3 4 |
# File 'lib/logic_analyzer/truth_table.rb', line 2 def iterations @iterations end |
#table ⇒ Object
Returns the value of attribute table.
2 3 4 |
# File 'lib/logic_analyzer/truth_table.rb', line 2 def table @table end |
#variables ⇒ Object
Returns the value of attribute variables.
2 3 4 |
# File 'lib/logic_analyzer/truth_table.rb', line 2 def variables @variables end |
Instance Method Details
#generate_table ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/logic_analyzer/truth_table.rb', line 10 def generate_table for iteration in 0...iterations row = [] for column in (variables.size - 1).downto 0 value = (iteration / 2 ** column).odd? row.append(value) end table.append(row) end table end |
#truth_value_of(variable, row) ⇒ Object
25 26 27 28 |
# File 'lib/logic_analyzer/truth_table.rb', line 25 def truth_value_of(variable, row) column = variables.find_index(variable) table.at(row).at(column) end |