Files
chapter-organizer/tools/GoogleSheetsScheduleImport/SchoolLevelPrefixParser.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

41 lines
1.6 KiB
C#

using Core.Models;
namespace GoogleSheetsScheduleImport;
/// <summary>
/// Strips leading MS / HS markers from grid titles so titles can be fuzzy-matched to <see cref="Core.Entities.EventDefinition.Name"/>.
/// </summary>
public static class SchoolLevelPrefixParser
{
/// <returns>Remainder text and school level when unambiguous; <c>null</c> level for MS/HS combined or unknown.</returns>
public static (string Remainder, SchoolLevel? Level) StripLeadingSchoolPrefix(string raw)
{
var s = TextNormalization.ForEmitLine(raw);
if (string.IsNullOrEmpty(s))
return (s, null);
if (s.StartsWith("MS/HS", StringComparison.OrdinalIgnoreCase))
{
var rest = s[5..].TrimStart();
if (rest.StartsWith('/'))
rest = rest[1..].TrimStart();
return (rest, null);
}
if (s.Length >= 3 && s.StartsWith("MS ", StringComparison.OrdinalIgnoreCase))
return (s[3..].TrimStart(), SchoolLevel.MiddleSchool);
if (s.Length >= 3 && s.StartsWith("HS ", StringComparison.OrdinalIgnoreCase))
return (s[3..].TrimStart(), SchoolLevel.HighSchool);
if (s.Length >= 3 && s.StartsWith("MS/", StringComparison.OrdinalIgnoreCase))
return (s[3..].TrimStart(), SchoolLevel.MiddleSchool);
if (s.Length >= 3 && s.StartsWith("HS/", StringComparison.OrdinalIgnoreCase))
return (s[3..].TrimStart(), SchoolLevel.HighSchool);
return (s, null);
}
public static string ToSectionSuffix(SchoolLevel level) =>
level == SchoolLevel.MiddleSchool ? "MS" : "HS";
}