Refactor event occurrence parsing to improve school level handling and section skipping
This commit refines the EventOccurrenceParser by replacing boolean flags for school sections with a more robust SchoolLevel enum. The logic for determining whether to skip events based on school level has been encapsulated in dedicated methods, enhancing readability and maintainability. Additionally, the EventOccurrenceParserService has been updated to detect potential missing line breaks in section headers, improving warning reporting. These changes streamline the parsing process and ensure accurate handling of event occurrences based on school level settings.
This commit is contained in:
@@ -197,6 +197,26 @@ public class EventOccurrenceParserService : IEventOccurrenceParserService
|
||||
result.Warnings.Add($"Location '{loc}' may contain date/time information: '{match.Value}'");
|
||||
}
|
||||
}
|
||||
|
||||
// Check for section header patterns (missing line break detection)
|
||||
// Pattern matches: text ending with " - MS", " - HS"
|
||||
// This indicates a missing line break where the next section header was concatenated to the location
|
||||
// Note: Input is already sanitized (en-dash/em-dash -> regular hyphen), so we only need to match regular hyphens
|
||||
var sectionHeaderPattern = new Regex(
|
||||
@"-\s*(MS|HS)\s*$",
|
||||
RegexOptions.IgnoreCase | RegexOptions.Compiled);
|
||||
|
||||
var locationsWithSectionHeader = locations.Where(loc => loc != null && sectionHeaderPattern.IsMatch(loc)).ToList();
|
||||
foreach (var loc in locationsWithSectionHeader)
|
||||
{
|
||||
if (loc != null)
|
||||
{
|
||||
var match = sectionHeaderPattern.Match(loc);
|
||||
// Extract the section header part for better warning message
|
||||
var sectionHeaderPart = match.Value.Trim();
|
||||
result.Warnings.Add($"Location '{loc}' appears to contain a section header (ends with '{sectionHeaderPart}') - likely missing line break. The location may be corrupted.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user