Skip to content

Commit

Permalink
Added filter processor to remove "comments" from Toggl entries
Browse files Browse the repository at this point in the history
  • Loading branch information
elca-lan committed Nov 3, 2021
1 parent 22151c7 commit 14d85eb
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/Toggl2Vertec/Processors/ProcessorModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public override void Load()
RegisterProcessor<SummaryRounding>();
RegisterProcessor<AttendanceProcessor>();
RegisterProcessor<ForceLunch>();
RegisterProcessor<TextCommentFilter>();
}

private void RegisterProcessor<TProcessor>()
Expand Down
65 changes: 65 additions & 0 deletions src/Toggl2Vertec/Processors/TextCommentFilter.cs
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)];
}
}
}
}
2 changes: 1 addition & 1 deletion src/Toggl2Vertec/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"profiles": {
"Toggl2Vertec": {
"commandName": "Project",
"commandLineArgs": "list 2021-09-06 --verbose"
"commandLineArgs": "list --verbose"
}
}
}
6 changes: 5 additions & 1 deletion src/Toggl2Vertec/t2v.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
},
{
"Name": "ForceLunch",
"StartAt": "12:00",
"StartAt": "12:00",
"Duration": 30
},
{
"Name": "TextCommentFilter",
"CommentMarker": "//"
}
]
}

0 comments on commit 14d85eb

Please sign in to comment.