public static IngredientData[] GetAllIngredients() { string dataAsJson = File.ReadAllText("Assets/JSON/ingredients.json"); AllIngredients ret = JsonUtility.FromJson <AllIngredients> (dataAsJson); return(ret.ingredients); }
public static IngredientData GetRandomIngredient() { if (allIngredients == null) { allIngredients = AllIngredients.GetAllIngredients(); } counter = (counter + 1) % 2; return(allIngredients [counter]); }
/// <summary> /// Filters the ingredients action. /// </summary> private void FilterIngredientsAction() { var filteredList = new ObservableCollection <IIngredient>(); foreach (var element in AllIngredients.Where(element => element.Name.ToLower().Contains(FilterText.ToLower() ?? ""))) { filteredList.Add(element); } FilteredIngredients = filteredList; }
private void AddIngredient() { if (String.IsNullOrWhiteSpace(NewIngredient)) { return; } if (!AllIngredients.Any(i => i.Name == NewIngredient)) { AllIngredients.Add(new Ingredient { Name = NewIngredient }); } Ingredients.Add(AllIngredients.First(i => i.Name == NewIngredient)); NewIngredient = String.Empty; }
public void ParseFoods(string food) { var parts = food.Replace("(", " ").Replace(")", " ").Split("contains"); List <string> ingredients = new List <string>(parts[0].Split(' ', StringSplitOptions.RemoveEmptyEntries)); List <string> allergens = new List <string>(parts[1].Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries)); foreach (var item in allergens) { if (AllergenIngredientsMap.ContainsKey(item)) { // Intersect the hashsets to get the common ingredients AllergenIngredientsMap[item].IntersectWith(ingredients); } else { HashSet <string> list = new HashSet <string>(ingredients); AllergenIngredientsMap.Add(item, list); } } AllIngredients.AddRange(ingredients); }
public void Parse() { Ingredients = AllIngredients.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); Allergens = AllAllergens.Replace("contains", "").Split(" ,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList(); }