From 4056a7ed6ba3ff2a19e9d2827be102b7e42bab2d Mon Sep 17 00:00:00 2001 From: Lynnesbian Date: Sat, 26 Sep 2020 23:16:54 +1000 Subject: [PATCH] forgot to add the new classes whoops --- .gitignore | 1 + Rule.cs | 35 +++++++++++++++++++++++++++++++++++ RuleMatch.cs | 9 +++++++++ 3 files changed, 45 insertions(+) create mode 100644 Rule.cs create mode 100644 RuleMatch.cs diff --git a/.gitignore b/.gitignore index 99f7018..35d5b10 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ bin/ obj/ test.csv +rules.json diff --git a/Rule.cs b/Rule.cs new file mode 100644 index 0000000..a632420 --- /dev/null +++ b/Rule.cs @@ -0,0 +1,35 @@ +using System; +using System.Text.RegularExpressions; + +namespace BunyMuny { + public class Rule { + public RuleMatch Match { get; set; } + public string Value { get; set; } + public string Category { get; set; } + public string Description { get; set; } + public bool CaseSensitive { get; set; } // TODO: make this have an effect + + /// + /// Checks whether or not a given value matches the rule. + /// + /// The string to check against the rule's Value. + /// + public bool Check(string input) { + switch (Match) { + case RuleMatch.Exact: + return input == Value; + case RuleMatch.Start: + return input.StartsWith(Value); + case RuleMatch.End: + return input.EndsWith(Value); + case RuleMatch.Regex: + var re = new Regex(Value); + return re.IsMatch(input); + case RuleMatch.Contains: + return input.Contains(input); + default: + return false; + } + } + } +} diff --git a/RuleMatch.cs b/RuleMatch.cs new file mode 100644 index 0000000..f2f1d7e --- /dev/null +++ b/RuleMatch.cs @@ -0,0 +1,9 @@ +namespace BunyMuny { + public enum RuleMatch { + Exact, + Start, + End, + Regex, + Contains + } +}