class TruthTable

Attributes

iterations[RW]
table[RW]
variables[RW]

Public Class Methods

new(variables) click to toggle source
# File lib/logic_analyzer/truth_table.rb, line 4
def initialize(variables)
  @variables = variables
  @iterations = 2 ** variables.size
  @table = []
end

Public Instance Methods

generate_table() click to toggle source
# 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) click to toggle source
# 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