<<

NAME

ProductOpener::Nutrition - functions related to nutrition facts of food products

DESCRIPTION

ProductOpener::Nutrition contains functions specific to food products, in particular related to the new schema of nutrition facts. This module provides functions It does not contain functions related to ingredients which are in the ProductOpener::Ingredients module.

..

FUNCTIONS

generate_nutrient_set_preferred_from_sets

Generates and returns a hash reference of the preferred nutrient set from the given list of nutrient sets.

The generated set is a combined set of nutrients with the preferred sources, per references and preparation states and with normalized units.

Arguments

$nutrient_sets_ref

Array of nutrients sets used to generate the preferred set

Return values

The generated preferred nutrient set

sort_sets_by_priority

Sorts hashes of nutrient sets in a given array based on a custom priority.

The priority is based on the sources, the per references and the preparation states present in the nutrient sets.

Arguments

@nutrient_sets

Unsorted array nutrient sets hashes

Return values

Sorted array nutrient sets hashes

set_nutrient_values

For each nutrient appearing in the nutrient sets array, sets its values in the preferred set.

The units of the nutrients quantities are normalized (g, kJ or kcal).

Each nutrient is only added once. Its value is the one in the set with the highest priority.

If the preparation value in a set is different from the one in the preferred set, the nutrient is not added to the preferred set.

Arguments

$nutrient_set_preferred_ref

The generated preferred nutrient set.

@nutrient_sets

The sorted array of nutrient set hashes used to generate the preferred set.

convert_nutrient_to_standard_unit

Normalizes the unit of the nutrient value if necessary.

The normalized units are g, kJ or kcal based on the nutrient.

Arguments

$nutrient_ref

Hash of the nutrient to normalize

$nutrient_name

Name of the nutrient to normalize

convert_nutrient_to_wanted_per

Converts the value of the amount of the nutrient based on the wanted per reference if necessary.

Arguments

$nutrient_ref

Hash of the nutrient set with the value to convert

$original_per_quantity

Current per amount of the nutrient

$original_per_unit

Current per unit of the nutrient

$wanted_per_quantity

Wanted per amount of the nutrient

$wanted_per_unit

Wanted per unit of the nutrient

<<