mirror of https://github.com/kcal-app/kcal.git
Add nutrients per serving methods to Recipe
This commit is contained in:
parent
013baa88fc
commit
e3e84c2e13
|
@ -84,6 +84,11 @@ class IngredientAmount extends Model
|
|||
|
||||
/**
|
||||
* Get the multiplier for the ingredient unit based on weight.
|
||||
*
|
||||
* Unit weight will be specified for ingredients that are added by unit
|
||||
* (e.g. eggs, vegetables, etc.) and cup weight (the weight of the
|
||||
* ingredient equal to one cup) will be specified for ingredients that are
|
||||
* measured (e.g. flour, milk, etc.).
|
||||
*/
|
||||
private function unitMultiplier(): float {
|
||||
return match ($this->unit) {
|
||||
|
|
|
@ -53,33 +53,61 @@ class Recipe extends Model
|
|||
}
|
||||
|
||||
/**
|
||||
* Get total recipe calories.
|
||||
* Get total calories.
|
||||
*/
|
||||
public function caloriesTotal(): float {
|
||||
return $this->sumNutrient('calories');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total recipe protein.
|
||||
* Get per serving calories.
|
||||
*/
|
||||
public function caloriesPerServing(): float {
|
||||
return $this->caloriesTotal() / $this->servings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total protein.
|
||||
*/
|
||||
public function proteinTotal(): float {
|
||||
return $this->sumNutrient('protein');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total recipe fat.
|
||||
* Get per serving protein.
|
||||
*/
|
||||
public function proteinPerServing(): float {
|
||||
return $this->proteinTotal() / $this->servings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total fat.
|
||||
*/
|
||||
public function fatTotal(): float {
|
||||
return $this->sumNutrient('fat');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total recipe carbohydrates.
|
||||
* Get per serving fat.
|
||||
*/
|
||||
public function fatPerServing(): float {
|
||||
return $this->fatTotal() / $this->servings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get total carbohydrates.
|
||||
*/
|
||||
public function carbohydratesTotal(): float {
|
||||
return $this->sumNutrient('carbohydrates');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get per serving carbohydrates.
|
||||
*/
|
||||
public function carbohydratesPerServing(): float {
|
||||
return $this->carbohydratesTotal() / $this->servings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sum a specific nutrient for all ingredient amounts.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue