Exemple #1
0
    public static IngredientData[] GetAllIngredients()
    {
        string         dataAsJson = File.ReadAllText("Assets/JSON/ingredients.json");
        AllIngredients ret        = JsonUtility.FromJson <AllIngredients> (dataAsJson);

        return(ret.ingredients);
    }
Exemple #2
0
    public static IngredientData GetRandomIngredient()
    {
        if (allIngredients == null)
        {
            allIngredients = AllIngredients.GetAllIngredients();
        }
        counter = (counter + 1) % 2;

        return(allIngredients [counter]);
    }
Exemple #3
0
        /// <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;
        }
Exemple #4
0
 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);
        }
Exemple #6
0
 public void Parse()
 {
     Ingredients = AllIngredients.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList();
     Allergens   = AllAllergens.Replace("contains", "").Split(" ,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
 }