Method Unit Coding

We add Method Unit Conversions to a plugin that is already reasonably complex. Here we consider how to approach this programming.

Mocha Tests for existing calculations. Given inputs and lines. Check expected outputs.

Constant Label Parsing. Recognize numerator units on constants. Construct object values with parsed versions.

Parse Unit Ratios. Recognize them. Represent them. Print them.

Parse Conversions. Save as {value, units, from}.

Coerce Outputs. Retrieve and apply conversions for outputs of operations.

Retrieve Conversions. Search available values from applicable from field.

Align Units. Look up conversion factors (maybe always 12 for debugging). This works differently for SUM and PRODUCT.

Compute Products Multiply and cancel units.

Coerce to Similar Units when possible, for products and ratios, so that squares and cubes are more likely recognized.

Compute Ratios. Handle canceling of units. Test to be sure representation is correct in every case.

SHOW Units. Create a units printer that handles squares, etc. Add same conventions to units parser.

Invert Factors to convert units in a reverse direction.

Generalize Coercion for all operators. Make errors consistent.

Generalize Conversions to be numbers as if to/from units.

Generalize Ratio to define computed conversions.

Assumed Units. Infer units based on preceding units in a list. This works differently for SUM and PRODUCT.

Excel from Reduce. Add conversions to output from the Reduce plugin. Add rows where conversions are applied. Add Columns to show parsed units. See cross-ref.coffee. gist