ProductOpener::Units - functions to convert units
Converts <xx><unit> into <xx> kcal.
Create a map of all synonyms in all languages in the units taxonomy to an internal standard unit and conversion factor Also create a regexp matching all names.
Converts <xx><unit> into <xx>grams. Eg.: unit_to_g(2,kg) => returns 2000 unit_to_g(520,mg) => returns 0.52
Converts <xx>grams into <xx><unit>. Eg.: g_to_unit(2000,kg) => returns 2 g_to_unit(0.52,mg) => returns 520
Returns the quantity ($q), the multiplicator ($m, optional) and the unit ($u) that may be found in the quantity field entered by contributors
parse_quantity_unit(1 barquette de 40g) returns (40, 1, g) parse_quantity_unit(20 tranches 500g) returns (500, 20, g) parse_quantity_unit(6x90g) returns (90, 6, g) parse_quantity_unit(2kg) returns (2, undef, kg)
Returns (undef, undef, undef) if no quantity was detected.
Returns the size in g or ml for the whole product. Eg.: normalize_quantity(1 barquette de 40g) returns 40 normalize_quantity(20 tranches 500g) returns 500 normalize_quantity(6x90g) returns 540 normalize_quantity(2kg) returns 2000
Returns undef if no quantity was detected.
Returns the standard_unit corresponding to the extracted unit
extract_standard_unit(1 barquette de 40g, 1) returns g extract_standard_unit(2kg) returns g extract_standard_unit(33cl) returns ml
Returns undef if no unit was detected.
Returns the size in g or ml for the serving. Eg.: normalize_serving_size(1 barquette de 40g)->returns 40 normalize_serving_size(2.5kg)->returns 2500
Normalize the product quantity and serving size fields.
Reference to a product.