forgot to add the new classes whoops
This commit is contained in:
parent
c5748a21d4
commit
4056a7ed6b
3 changed files with 45 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -2,3 +2,4 @@
|
|||
bin/
|
||||
obj/
|
||||
test.csv
|
||||
rules.json
|
||||
|
|
35
Rule.cs
Normal file
35
Rule.cs
Normal file
|
@ -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
|
||||
|
||||
/// <summary>
|
||||
/// Checks whether or not a given value matches the rule.
|
||||
/// </summary>
|
||||
/// <param name="input">The string to check against the rule's Value.</param>
|
||||
/// <returns></returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
RuleMatch.cs
Normal file
9
RuleMatch.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
namespace BunyMuny {
|
||||
public enum RuleMatch {
|
||||
Exact,
|
||||
Start,
|
||||
End,
|
||||
Regex,
|
||||
Contains
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue