Water percentages
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import Units
|
||||
|
||||
public class Product: Codable, ObjectDebugger {
|
||||
// public var images: Images? = Images()
|
||||
public var ingredients: [Ingredient]? = []
|
||||
@@ -200,6 +202,23 @@ public class Product: Codable, ObjectDebugger {
|
||||
public var vitaminsPrevTags: [String]?
|
||||
public var vitaminsTags: [String]?
|
||||
|
||||
public var waterQuantity: Units.UnitValue<Double>? {
|
||||
guard let ingredient = ingredients?.first(where: { $0.isWater })
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
||||
guard let quantity = productQuantity,
|
||||
let estimate = ingredient.percentEstimate,
|
||||
let rawUnit = productQuantityUnit,
|
||||
let unit = Units.Unit(rawValue: rawUnit)
|
||||
else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return Double(quantity * (estimate / 100))[unit]
|
||||
}
|
||||
|
||||
private enum CodingKeys: String, CodingKey {
|
||||
// case images
|
||||
case ingredients
|
||||
|
||||
Reference in New Issue
Block a user