In complex system measurement sometimes go beyond a simple sum of value, Nabiro introduced in the 0.9016 release a simple support for
* Unit
* Quantity
* ConversionRatio
The Unit class is used to define strongly typed unit in the system, the Quantity class is a way you can represents quantity in complex systems that use strongly typed Unit, the ConversionRatio? class is a simple conversion system, in order to handle complex conversion like Celsius to Fahrenheit you can override the converter method of the class.
Simple usage
dollar = new Dollar(); dollar.symbol = "$"; dollar.value = 1; var bc:BasketCost = new BasketCost(); bc.amount = 5; bc.unit = dollar; var vect:Vector.<Unit> = new Vector.<Unit>(); vect[0] = dollar; vect[1] = dollar; vect[2] = dollar; vect[3] = dollar; bc.sum(vect); trace(bc.toString()) feet = new Feet(); feet.symbol = "ft"; feet.value = 1; var ch:CanvasHeight = new CanvasHeight(); ch.unit = feet; ch.amount = 10; trace(ch.toString()); var cr:ConversionRatio = new ConversionRatio(12); trace(cr.convertTo(ch))
Attached files contain the full example.
Attachments
- MeasuremenHandling.zip (283.1 KB) - added by GiorgioNatili 13 months ago.