-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added filter processor to remove "comments" from Toggl entries
- Loading branch information
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Toggl2Vertec.Configuration; | ||
using Toggl2Vertec.Logging; | ||
using Toggl2Vertec.Tracking; | ||
|
||
namespace Toggl2Vertec.Processors | ||
{ | ||
public class TextCommentFilter : IWorkingDayProcessor | ||
{ | ||
private readonly ICliLogger _logger; | ||
private readonly ProcessorSettings _settings; | ||
|
||
public TextCommentFilter(ICliLogger logger, ProcessorSettings settings) | ||
{ | ||
_logger = logger; | ||
_settings = settings; | ||
} | ||
|
||
public WorkingDay Process(WorkingDay workingDay) | ||
{ | ||
workingDay.Summaries = workingDay.Summaries.Select(summary => | ||
{ | ||
if (summary.Text.Any(text => text.Contains(_settings.CommentMarker))) | ||
{ | ||
return new SummaryGroup(summary.Title, summary.Duration, summary.Text.Select(text => | ||
{ | ||
var commentIndex = text.IndexOf(_settings.CommentMarker); | ||
if (commentIndex >= 0) | ||
{ | ||
_logger.LogInfo($"Removing comment from text fragment '{text}'"); | ||
return text.Substring(0, commentIndex).Trim(); | ||
} | ||
else | ||
{ | ||
return text; | ||
} | ||
}).ToList()); | ||
} | ||
else | ||
{ | ||
return summary; | ||
} | ||
}); | ||
|
||
return workingDay; | ||
} | ||
|
||
public class ProcessorSettings | ||
{ | ||
private readonly ProcessorDefinition _processor; | ||
|
||
public string CommentMarker { get; } | ||
|
||
public ProcessorSettings(ProcessorDefinition processor) | ||
{ | ||
_processor = processor; | ||
CommentMarker = _processor.Section[nameof(CommentMarker)]; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters