diff --git a/.gitignore b/.gitignore
index dcaa92c..912d71a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ bin/
obj/
test.csv
rules.csv
+.~lock*
diff --git a/Program.cs b/Program.cs
index 09309b5..59fefbe 100644
--- a/Program.cs
+++ b/Program.cs
@@ -68,7 +68,7 @@ namespace BunyMuny {
while (csv.Read()) {
switch (bank) {
case Bank.ME:
- var value = double.Parse(csv.GetField("Debits and credits").TrimStart().Replace("$", ""));
+ var value = decimal.Parse(csv.GetField("Debits and credits").TrimStart().Replace("$", ""));
var (category, description) = MatchAgainstRules(rules, csv.GetField("Description"));
statements.Add(new Statement() {
@@ -95,11 +95,28 @@ namespace BunyMuny {
}
foreach (var statement in statements.
- // Where(s => s.Category != null).
+ // Where(s => s.Category == null).
OrderBy(s => s.Date)) {
Console.WriteLine(statement);
}
+ Console.WriteLine("Summary:");
+ Console.WriteLine("==================");
+ var summaries = statements.
+ GroupBy(s => s.Category). // group statements by category
+ Select(summary => new { // and then select:
+ Name = summary.First().Category?? "Other", // the name of the category...
+ Total = summary.Sum(s => s.Value).ToString() // ...and the sum of all the statement's values in that category
+ });
+
+ var longestCategoryName = summaries.
+ ToList().
+ Max(summary => summary.Name.Length);
+
+ foreach (var summary in summaries) {
+ Console.WriteLine("{0}: {1}", summary.Name.PadLeft(longestCategoryName), summary.Total);
+ }
+
return 0;
}
diff --git a/Rule.cs b/Rule.cs
index a632420..9045121 100644
--- a/Rule.cs
+++ b/Rule.cs
@@ -15,18 +15,23 @@ namespace BunyMuny {
/// The string to check against the rule's Value.
///
public bool Check(string input) {
+ var value = Value;
+ if (!CaseSensitive) {
+ input = input.ToLower();
+ value = value.ToLower();
+ }
switch (Match) {
case RuleMatch.Exact:
- return input == Value;
+ return input == value;
case RuleMatch.Start:
- return input.StartsWith(Value);
+ return input.StartsWith(value);
case RuleMatch.End:
- return input.EndsWith(Value);
+ return input.EndsWith(value);
case RuleMatch.Regex:
- var re = new Regex(Value);
+ var re = new Regex(value);
return re.IsMatch(input);
case RuleMatch.Contains:
- return input.Contains(input);
+ return input.Contains(value);
default:
return false;
}
diff --git a/Statement.cs b/Statement.cs
index cdddb0e..5d51094 100644
--- a/Statement.cs
+++ b/Statement.cs
@@ -11,7 +11,7 @@ namespace BunyMuny {
}
public string OriginalDescription;
- public double Value;
+ public decimal Value;
public string Category;
public override string ToString() {