Multiple changes and improvements

* Base and NicotineBase separated
* Importer bugfixed
* Mixer improved
This commit is contained in:
2019-07-09 02:10:56 +02:00
parent 6e662f0263
commit 922d9f09dd
14 changed files with 302 additions and 44 deletions

View File

@ -22,47 +22,96 @@ class MeasuredIngredient implements IngredientInterface
/** @var float Weight in grams (g) */
protected $weight;
public function __construct(string $name, ?string $brand, string $base, float $asg, float $percent, float $volume)
/**
* MeasuredIngredient constructor
*
* @param IngredientInterface|string The ingredient
* @param float The percent of the ingredient to use
* @param float The volume of the ingredient to mix (in mL)
* @param string The base of the ingredient, override any set on ingredient
*/
public function __construct($ingredient, float $percent, float $volume, string $base=null)
{
$this->name = $name;
$this->brand = $brand;
$this->base = $base;
if ($ingredient instanceof IngredientInterface) {
$asg = $ingredient->getSpecificGravity();
$this->name = $ingredient->getFlavorName();
$this->brand = $ingredient->getFlavorBrand();
$this->base = $base??$ingredient->getBase();
} else {
$asg = null;
$this->name = $ingredient;
$this->base = $base??"PG100";
}
if (!$asg) {
$base = new Base($this->base);
$asg = $base->getSpecificGravity();
}
$this->asg = $asg;
$this->percent = $percent;
$this->volume = $volume;
$this->weight = $volume * $asg;
}
/**
*
* @return string
*/
public function getFlavorName(): string
{
return $this->name;
}
/**
*
* @return string|null
*/
public function getFlavorBrand(): ?string
{
return $this->brand;
}
/**
*
* @return string|null
*/
public function getBase(): ?string
{
return $this->base;
}
/**
*
* @return float
*/
public function getPercent(): float
{
return $this->percent;
}
/**
*
* @return float
*/
public function getSpecificGravity(): float
{
return $this->asg;
}
/**
*
* @return float
*/
public function getVolume(): float
{
return $this->volume;
}
/**
*
* @return float
*/
public function getWeight(): float
{
return $this->weight;