<<

NAME

ProductOpener::Units - functions to convert units

DESCRIPTION

FUNCTIONS

unit_to_kcal($value, $unit)

Converts <xx><unit> into <xx> kcal.

init_units_names()

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.

unit_to_g($value, $unit)

Converts <xx><unit> into <xx>grams. Eg.: unit_to_g(2,kg) => returns 2000 unit_to_g(520,mg) => returns 0.52

g_to_unit($value, $unit)

Converts <xx>grams into <xx><unit>. Eg.: g_to_unit(2000,kg) => returns 2 g_to_unit(0.52,mg) => returns 520

parse_quantity_unit($quantity)

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.

normalize_quantity($quantity)

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.

extract_standard_unit($quantity)

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.

normalize_serving_size($serving)

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_product_quantity_and_serving_size ($product_ref)

Normalize the product quantity and serving size fields.

Parameters

$product_ref

Reference to a product.

<<