Update EventOccurrence parsing to use EventOccurrenceParseGroup for improved data structure
This commit refactors the EventOccurrence parsing logic to utilize the EventOccurrenceParseGroup class, enhancing the organization of parsed occurrences by grouping them based on event definitions and optional section levels. The changes include updates to the EventOccurrenceParseResult, EventOccurrenceParser, and EventOccurrenceParserService to accommodate the new grouping structure. Additionally, tests are modified to reflect these changes, ensuring that the parsing functionality remains intact and accurate. This refactor improves data handling and aligns with the overall architecture of the application.
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using Core.Entities;
|
||||
using Core.Models;
|
||||
|
||||
namespace GoogleSheetsScheduleImport;
|
||||
|
||||
/// <summary>
|
||||
/// For grouped output, occurrence lines should look like the PDF schedule: activity text only, not
|
||||
/// <c>MS EventName Activity</c> when the section is already <c>EventName - MS</c>.
|
||||
/// </summary>
|
||||
public static class OccurrenceDisplayNameReducer
|
||||
{
|
||||
public static string ReduceForSection(string occurrenceName, EventDefinition matched, SchoolLevel level)
|
||||
{
|
||||
var (remainder, lvl) = SchoolLevelPrefixParser.StripLeadingSchoolPrefix(occurrenceName);
|
||||
if (!lvl.HasValue || lvl.Value != level)
|
||||
return TextNormalization.ForEmitLine(occurrenceName);
|
||||
|
||||
var r = remainder.Trim();
|
||||
var eventName = matched.Name.Trim();
|
||||
if (r.StartsWith(eventName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
r = r[eventName.Length..].TrimStart();
|
||||
r = TrimLeadingJoiners(r);
|
||||
}
|
||||
|
||||
r = TextNormalization.ForEmitLine(r);
|
||||
if (string.IsNullOrWhiteSpace(r))
|
||||
return TextNormalization.ForEmitLine(remainder.Trim());
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
private static string TrimLeadingJoiners(string s)
|
||||
{
|
||||
var r = s;
|
||||
while (r.Length > 0)
|
||||
{
|
||||
var c = r[0];
|
||||
if (c is '/' or '-' or ':' or '&' or '–' or '—' or ',' or '.')
|
||||
{
|
||||
r = r[1..].TrimStart();
|
||||
continue;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return r;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user