Water percentages
This commit is contained in:
@@ -7,6 +7,9 @@ public struct Ingredient: Codable, ObjectDebugger {
|
|||||||
public var text: String? = nil
|
public var text: String? = nil
|
||||||
public var vegan: String? = nil
|
public var vegan: String? = nil
|
||||||
public var vegetarian: String? = nil
|
public var vegetarian: String? = nil
|
||||||
|
public var ciqualFoodCode: String? = nil
|
||||||
|
public var ecobalyseCode: String? = nil
|
||||||
|
public var percentEstimate: Float? = nil
|
||||||
|
|
||||||
private enum CodingKeys: String, CodingKey {
|
private enum CodingKeys: String, CodingKey {
|
||||||
case fromPalmOil = "from_palm_oil"
|
case fromPalmOil = "from_palm_oil"
|
||||||
@@ -17,5 +20,12 @@ public struct Ingredient: Codable, ObjectDebugger {
|
|||||||
case text
|
case text
|
||||||
case vegan
|
case vegan
|
||||||
case vegetarian
|
case vegetarian
|
||||||
|
case ciqualFoodCode = "ciqual_food_code"
|
||||||
|
case ecobalyseCode = "ecobalyse_code"
|
||||||
|
case percentEstimate = "percent_estimate"
|
||||||
|
}
|
||||||
|
|
||||||
|
public var isWater: Bool {
|
||||||
|
ciqualFoodCode == "18066"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import Units
|
||||||
|
|
||||||
public class Product: Codable, ObjectDebugger {
|
public class Product: Codable, ObjectDebugger {
|
||||||
// public var images: Images? = Images()
|
// public var images: Images? = Images()
|
||||||
public var ingredients: [Ingredient]? = []
|
public var ingredients: [Ingredient]? = []
|
||||||
@@ -200,6 +202,23 @@ public class Product: Codable, ObjectDebugger {
|
|||||||
public var vitaminsPrevTags: [String]?
|
public var vitaminsPrevTags: [String]?
|
||||||
public var vitaminsTags: [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 {
|
private enum CodingKeys: String, CodingKey {
|
||||||
// case images
|
// case images
|
||||||
case ingredients
|
case ingredients
|
||||||
|
|||||||
Reference in New Issue
Block a user