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.
26 lines
893 B
C#
26 lines
893 B
C#
using System.Text.RegularExpressions;
|
|
|
|
namespace GoogleSheetsScheduleImport;
|
|
|
|
public static class SpreadsheetId
|
|
{
|
|
private static readonly Regex IdRegex = new(
|
|
@"/spreadsheets/d/([a-zA-Z0-9-_]+)",
|
|
RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
|
|
|
/// <summary>
|
|
/// Extracts spreadsheet id from a full Google Sheets URL or returns the string if it already looks like an id.
|
|
/// </summary>
|
|
public static string FromUrlOrId(string input)
|
|
{
|
|
var trimmed = input.Trim();
|
|
var m = IdRegex.Match(trimmed);
|
|
if (m.Success)
|
|
return m.Groups[1].Value;
|
|
if (trimmed.Length > 20 && !trimmed.Contains('/') && !trimmed.Contains(':'))
|
|
return trimmed;
|
|
throw new ArgumentException(
|
|
"Expected a Google Sheets URL (…/spreadsheets/d/{id}/…) or a raw spreadsheet id.", nameof(input));
|
|
}
|
|
}
|