From c1e79e5c0cc8284fb789609afd91fec55db834a6 Mon Sep 17 00:00:00 2001 From: Bradley Faskowitz Date: Thu, 16 May 2024 00:04:13 -0300 Subject: [PATCH] Add GameStatus enum --- src/Enums/StatusCode.cs | 13 +++++++++++++ src/MLBClient.cs | 2 +- src/Models/Schedule.cs | 24 ++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/Enums/StatusCode.cs diff --git a/src/Enums/StatusCode.cs b/src/Enums/StatusCode.cs new file mode 100644 index 0000000..9a79184 --- /dev/null +++ b/src/Enums/StatusCode.cs @@ -0,0 +1,13 @@ +namespace BaseballSharp.Enums; +/// +/// Represents the status of the game using predefined status codes. Note that there may be more codes than these -- +/// these are the status codes observed manually. +/// +public enum GameStatus +{ + Final, // "F" + InProgress, // "I" + Delayed, // "IR" + PreGame, // "P" + Scheduled // "S" +} diff --git a/src/MLBClient.cs b/src/MLBClient.cs index 912a046..c872e5d 100644 --- a/src/MLBClient.cs +++ b/src/MLBClient.cs @@ -52,7 +52,7 @@ public async Task> GetScheduleAsync(DateTime date) AwayTeam = game.teams?.away?.team?.name, HomeTeam = game.teams?.home?.team?.name, ScheduledInnings = game.scheduledInnings, - StatusCode = game.status?.statusCode + StatusCode = Schedule.GetStatusCode(game.status?.statusCode) }); } } diff --git a/src/Models/Schedule.cs b/src/Models/Schedule.cs index 693f718..56f9fcd 100644 --- a/src/Models/Schedule.cs +++ b/src/Models/Schedule.cs @@ -1,4 +1,6 @@ -namespace BaseballSharp.Models; +using BaseballSharp.Enums; + +namespace BaseballSharp.Models; public class Schedule { @@ -20,5 +22,23 @@ public class Schedule /// The status of the game. A few possible codes are "F" for Final, "I" for In Progress, /// "IR" for Delayed, "P" for Pre-game, and "S" for Sceduled. /// - public string? StatusCode { get; set; } + public GameStatus? StatusCode { get; set; } + + /// + /// Gets the GameStatus enum value based on the provided status code string. + /// + /// The status code string. + /// The corresponding GameStatus enum value, or null if the status code is unknown. + public static GameStatus? GetStatusCode(string? statusCode) + { + return statusCode switch + { + "F" => GameStatus.Final, + "I" => GameStatus.InProgress, + "IR" => GameStatus.Delayed, + "P" => GameStatus.PreGame, + "S" => GameStatus.Scheduled, + _ => null, + }; + } } \ No newline at end of file