public void When_Parsing_an_ingredient_with_a_complex_fractional_quantity_and_complex_notes() { // Arrange var inputString = "3 1/2 cup diced onions -- use yellow onions"; var recipeParserConfiguration = new ParserConfiguration { ReportExceptions = true }; var ingredientParser = new IngredientParser(recipeParserConfiguration); var ingredient = new RecipeIngredient { Quantity = 3.5, Units = "cup", Ingredient = "onions", Notes = "diced, use yellow onions" }; // Act var output = ingredientParser.Parse(inputString); // Assert Assert.NotNull(output); Assert.Equal(ingredient.Quantity, output.Quantity); Assert.Equal(ingredient.Units, output.Units); Assert.Equal(ingredient.Ingredient, output.Ingredient); Assert.Equal(ingredient.Notes, output.Notes); }
public FoodDetailsModels(string jsonString) { JObject detailObject = JObject.Parse(jsonString); string userID = System.Web.HttpContext.Current.User.Identity.GetUserId(); Description = detailObject.SelectToken("description")?.ToString() ?? ""; BrandOwner = detailObject.SelectToken("brandOwner")?.ToString() ?? ""; var ingredientString = detailObject.SelectToken("ingredients")?.ToString() ?? ""; if (!string.IsNullOrEmpty(ingredientString)) { var primary = new List <Ingredient>(); var secondary = new List <Ingredient>(); IngredientParser.Parse(ingredientString, out primary, out secondary); PrimaryIngredients = primary; SecondaryIngredients = secondary; } double servingSize; ServingSize = double.TryParse(detailObject.SelectToken("servingSize")?.ToString() ?? "", out servingSize) ? servingSize : 0.0; ServingSizeUnit = detailObject.SelectToken("servingSizeUnit")?.ToString() ?? ""; ServingSizeFullText = ServingSizeCleaner.Clean(detailObject.SelectToken("householdServingFullText")?.ToString() ?? ""); LabelNutrients = detailObject.SelectToken("labelNutrients")?.ToString() ?? ""; int fdcId; FdcId = int.TryParse(detailObject.SelectToken("fdcId")?.ToString() ?? "", out fdcId) ? fdcId : -1; UPC = detailObject.SelectToken("gtinUpc")?.ToString() ?? ""; MaxFodmapPercentage = Math.Round(Algorithm.GetMaxFodmapPercentage(PrimaryIngredients, SecondaryIngredients), 2); FodmapScore = MaxFodmapPercentage > 5 ? $"{Score.High}" : MaxFodmapPercentage > 0 ? $"{Score.Medium}" : $"{Score.Low}"; }
public void When_Parsing_a_properly_formed_ingredient() { // Arrange var inputString = "1 cup diced onions"; var recipeParserConfiguration = new ParserConfiguration { ReportExceptions = true }; var ingredientParser = new IngredientParser(recipeParserConfiguration); var ingredient = new RecipeIngredient { Quantity = 1, Units = "cup", Ingredient = "onions", Notes = "diced" }; // Act var output = ingredientParser.Parse(inputString); // Assert Assert.NotNull(output); Assert.Equal(ingredient.Quantity, output.Quantity); Assert.Equal(ingredient.Units, output.Units); Assert.Equal(ingredient.Ingredient, output.Ingredient); Assert.Equal(ingredient.Notes, output.Notes); }
public void When_parsing_a_complex_ingredient() { // Arrange var inputString = "2 lbs. top round, bottom round or stew beef cut into 2 inch pieces "; var recipeParserConfiguration = new ParserConfiguration { ReportExceptions = true }; var ingredientParser = new IngredientParser(recipeParserConfiguration); var ingredient = new RecipeIngredient { Quantity = 2, Units = "lbs", Ingredient = "top round", Notes = "top round, bottom round or stew beef cut into 2 inch pieces" }; // Act var output = ingredientParser.Parse(inputString); // Assert Assert.NotNull(output); Assert.Equal(ingredient.Quantity, output.Quantity); Assert.Equal(ingredient.Units, output.Units); Assert.Equal(ingredient.Ingredient, output.Ingredient); Assert.Equal(ingredient.Notes, output.Notes); }
private void parseDB() { string query = "SELECT [Ingredient.Name], [Ingredient.Price], [Ingredient.Type] FROM Ingredient"; OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, ConnectionString); DataSet ds = new DataSet(); dataAdapter.Fill(ds, "Ingredient"); foreach (DataRow row in ds.Tables[0].Rows) { Ingredients.Add(IngredientParser.parseIngredient(row[0].ToString(), row[1].ToString(), row[2].ToString())); } }
/// <summary>Generates the Ingredients and Steps</summary> public void ProcessRecipe() { this.Steps = new List <string>(); if (!String.IsNullOrEmpty(this.StepsText)) { string[] lines = this.StepsText.Split(new string[] { "\n", "\r\n" }, StringSplitOptions.None); this.Steps = new List <string>(lines); } IngredientParser parser = new IngredientParser(); this.Ingredients = parser.Parse(this.IngredientsText); }
public void Setup() { _parser = new IngredientParser(); }