src/JsonLdRecipeParser/Amount.cs
+13
-18
diff --git a/src/JsonLdRecipeParser/Amount.cs b/src/JsonLdRecipeParser/Amount.cs
index 3ed19cd..68ba9fb 100644
@@ -18,31 +18,26 @@ public partial record Amount
public required AmountValue Value { get; set; }
public string? Unit { get; set; }
[return: NotNullIfNotNull(nameof(quantity))]
internal static Amount? From(Quantity? quantity) =>
quantity?.Value switch
{
double d => new Amount { Value = new ExactAmountValue(d) },
string q when TryParse(q, out var amount) => amount,
QuantitativeValue q => new()
string q => TryParse(q, out var amount) ? amount : null,
QuantitativeValue q => q.Value?.Value switch
{
Value = q.Value?.Value switch
{
double v => new ExactAmountValue(v),
string v when TryParseValue(v, out var value) => value,
_ => throw new Exception(),
},
Unit = q.UnitText ?? q.UnitCode,
double v => new() { Value = new ExactAmountValue(v), Unit = q.UnitText ?? q.UnitCode },
string v => TryParseValue(v, out var value)
? new() { Value = value, Unit = q.UnitText ?? q.UnitCode }
: null,
_ => throw new Exception(),
},
PropertyValue p => new()
PropertyValue p => p.Value?.Value switch
{
Value = p.Value?.Value switch
{
double v => new ExactAmountValue(v),
string v when TryParseValue(v, out var value) => value,
_ => throw new Exception(),
},
Unit = p.UnitText ?? p.UnitCode,
double v => new() { Value = new ExactAmountValue(v), Unit = p.UnitText ?? p.UnitCode },
string v => TryParseValue(v, out var value)
? new() { Value = value, Unit = p.UnitText ?? p.UnitCode }
: null,
_ => throw new Exception(),
},
null => null,
_ => throw new Exception(),
src/JsonLdRecipeParser/Ingredient.cs
+2
-2
diff --git a/src/JsonLdRecipeParser/Ingredient.cs b/src/JsonLdRecipeParser/Ingredient.cs
index 58b143e..3f8a771 100644
@@ -12,10 +12,10 @@ public record Ingredient
public required string Name { get; set; }
public Amount? Amount { get; set; }
internal static Ingredient From(RecipeIngredient ingredient) =>
internal static Ingredient? From(RecipeIngredient ingredient) =>
ingredient.Value switch
{
string text when TryParse(text, out var i) => i,
string text => TryParse(text, out var i) ? i : null,
_ => throw new NotImplementedException("Ingredient parsing is only implemented for strings."),
};
src/JsonLdRecipeParser/JsonLdRecipeParser.csproj
+1
-1
diff --git a/src/JsonLdRecipeParser/JsonLdRecipeParser.csproj b/src/JsonLdRecipeParser/JsonLdRecipeParser.csproj
index 82862bd..2dd05bd 100644
@@ -5,7 +5,7 @@
</PropertyGroup>
<PropertyGroup>
<PackageId>JsonLdRecipeParser</PackageId>
<Version>0.0.4</Version>
<Version>0.0.5</Version>
<Authors>Mårten Åsberg</Authors>
<Company>MoreTec</Company>
<Description>Parses JSON-LD to a common recipe format.</Description>
src/JsonLdRecipeParser/Recipe.cs
+3
-1
diff --git a/src/JsonLdRecipeParser/Recipe.cs b/src/JsonLdRecipeParser/Recipe.cs
index d66699b..2e97822 100644
@@ -67,7 +67,9 @@ public class Recipe
TotalTime = recipe.TotalTime,
PrepTime = recipe.PrepTime,
CookTime = recipe.CookTime,
Ingredients = recipe.RecipeIngredient is null ? [] : [.. recipe.RecipeIngredient.Select(Ingredient.From)],
Ingredients = recipe.RecipeIngredient is null
? []
: [.. recipe.RecipeIngredient.Select(Ingredient.From).OfType<Ingredient>()],
InstructionSections = recipe.RecipeInstructions is null
? []
: [.. recipe.RecipeInstructions.Select(InstructionSection.From)],