class Belir::System

Represents a set or System of Equations

Public Class Methods

new(*equations) click to toggle source
# File lib/belir.rb, line 25
def initialize(*equations)
  @equations = equations
end

Public Instance Methods

add_equation(eqn) click to toggle source
# File lib/belir.rb, line 29
def add_equation(eqn)
  @equations.push(eqn)
end
solve(vars) click to toggle source
# File lib/belir.rb, line 33
def solve(vars)
  begin
    found = false
    @equations.each do |eqn|
      if vars[eqn.output].nil? && eqn.inputs.all? { |input| vars.key? input }
        args = []
        eqn.inputs.each do |input|
          args.push vars[input]
        end
        vars[eqn.output] = eqn.calculate(*args) # Splat to prevent [[2, 3]]
        found = true
      end
    end
  end while found
  vars
end