Add nutrients per serving methods to Recipe

This commit is contained in:
Christopher C. Wells 2020-12-22 15:11:13 -08:00
parent 013baa88fc
commit e3e84c2e13
2 changed files with 37 additions and 4 deletions

View File

@ -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) {

View File

@ -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.
*