Skip to content

Commit

Permalink
Add GameStatus enum
Browse files Browse the repository at this point in the history
  • Loading branch information
brfaskow committed May 16, 2024
1 parent 170ed45 commit c1e79e5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
13 changes: 13 additions & 0 deletions src/Enums/StatusCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace BaseballSharp.Enums;
/// <summary>
/// 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.
/// </summary>
public enum GameStatus
{
Final, // "F"
InProgress, // "I"
Delayed, // "IR"
PreGame, // "P"
Scheduled // "S"
}
2 changes: 1 addition & 1 deletion src/MLBClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public async Task<IEnumerable<Schedule>> 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)
});
}
}
Expand Down
24 changes: 22 additions & 2 deletions src/Models/Schedule.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
namespace BaseballSharp.Models;
using BaseballSharp.Enums;

namespace BaseballSharp.Models;

public class Schedule
{
Expand All @@ -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.
/// </summary>
public string? StatusCode { get; set; }
public GameStatus? StatusCode { get; set; }

/// <summary>
/// Gets the GameStatus enum value based on the provided status code string.
/// </summary>
/// <param name="statusCode">The status code string.</param>
/// <returns>The corresponding GameStatus enum value, or null if the status code is unknown.</returns>
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,
};
}
}

0 comments on commit c1e79e5

Please sign in to comment.