Files
chapter-organizer/tools/GoogleSheetsScheduleImport/OccurrenceDisplayNameReducer.cs
T
poprhythm f400813667 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.
2026-04-04 21:55:44 -04:00

51 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}