Class: AsciiChem::Linter::BalanceCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/asciichem/linter/balance_check.rb

Overview

Verifies that a reaction is stoichiometrically balanced — the atom counts on the reactants side equal those on the products side. Coefficients and group multiplicities are applied.

The check ignores electrons (e^-), conditions, and the arrow kind. It treats unknown constructs conservatively: any molecule it can't enumerate atoms for is skipped, not flagged.

Instance Method Summary collapse

Methods inherited from Base

register

Instance Method Details

#run(formula) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/asciichem/linter/balance_check.rb', line 15

def run(formula)
  diagnostics = []
  walk(formula) do |node|
    next unless node.is_a?(AsciiChem::Model::Reaction)

    check_reaction(node, diagnostics)
  end
  diagnostics
end