Esempio n. 1
0
        public RuleResult ProcessRule(RuleDescription ruleDescription)
        {
            var currentPlant = Plants[CurrentPlantIndex];
            var ruleResult   = new RuleResult {
                HasChanged = false, Result = currentPlant
            };

            var    startingIndex = CurrentPlantIndex - 2;
            string testPlants    = PlantContext();
            // if (startingIndex < 0)
            // {
            //     testPlants = $"..{Plants.Substring(CurrentPlantIndex, 3)}";
            // }
            // else
            // {
            //     testPlants = Plants.Substring(CurrentPlantIndex - 2, 5);
            // }

            var ruleMatches = (testPlants == ruleDescription.Specifier);

            if (ruleMatches && currentPlant != ruleDescription.Result)
            {
                ruleResult.HasChanged = true;
                ruleResult.Result     = ruleDescription.Result;
            }

            return(ruleResult);
        }
Esempio n. 2
0
        public RuleDescription ProcessRule(string ruleDescription)
        {
            var description = new RuleDescription();
            var ruleRegex   = new Regex(rulePattern);

            var matches = ruleRegex.Match(ruleDescription);

            if (!matches.Success)
            {
                throw new ArgumentException($"Could not parse {ruleDescription} as a rule");
            }

            description.Specifier = matches.Groups[1].Value;
            description.Result    = matches.Groups[2].Value.First();

            return(description);
        }