Skip to content

Commit

Permalink
Delete CsvRow
Browse files Browse the repository at this point in the history
  • Loading branch information
wgnf committed Oct 23, 2021
1 parent b5c528f commit 8f9f4c3
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 0 additions & 4 deletions src/CsvProc9000/Csv/CsvColumn.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/CsvProc9000/Csv/CsvField.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace CsvProc9000.Csv
{
public record CsvField(CsvColumn Column, string Value);
public record CsvField(string FieldName, string Value);
}
8 changes: 4 additions & 4 deletions src/CsvProc9000/Csv/CsvRow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ public class CsvRow

public IEnumerable<CsvField> Fields => _fields;

public void AddOrUpdateField([NotNull] string columnName, [NotNull] string fieldValue)
public void AddOrUpdateField([NotNull] string fieldName, [NotNull] string fieldValue)
{
if (columnName == null) throw new ArgumentNullException(nameof(columnName));
if (string.IsNullOrWhiteSpace(fieldName))
throw new ArgumentException("Value cannot be null or whitespace.", nameof(fieldName));
if (fieldValue == null) throw new ArgumentNullException(nameof(fieldValue));

var column = new CsvColumn(columnName);
_fields.Add(new CsvField(column, fieldValue));
_fields.Add(new CsvField(fieldName, fieldValue));
}
}
}
11 changes: 9 additions & 2 deletions src/CsvProc9000/Processors/CsvProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.IO;
using System.IO.Abstractions;
using System.Linq;
Expand Down Expand Up @@ -115,6 +115,13 @@ private void ApplyRuleToRow(CsvRow row, Rule rule, CsvFile file)

foreach (var (columnName, fieldValue) in rule.Steps)
{
if (string.IsNullOrWhiteSpace(columnName))
{
_logger.LogWarning("Processor: Not applying step for rule at index {RuleIndex} because no field name given",
_processorOptions.Rules.IndexOf(rule));
continue;
}

_logger.LogTrace("Processor: Row at index {RowIndex}: Adding field '{Field}' with value '{FieldValue}'",
_processorOptions.Rules.IndexOf(rule), columnName, fieldValue);
row.AddOrUpdateField(columnName, fieldValue);
Expand All @@ -125,7 +132,7 @@ private bool MeetsRowConditions(CsvRow row, Rule rule, CsvFile file)
{
foreach (var condition in rule.Conditions)
{
var field = row.Fields.FirstOrDefault(field => field.Column.Name == condition.Field);
var field = row.Fields.FirstOrDefault(field => field.FieldName == condition.Field);
if (field == null)
{
_logger.LogTrace(
Expand Down

0 comments on commit 8f9f4c3

Please sign in to comment.