fn extract_rank_info(rank_data: &HashMap<String, Value>) -> ValueExpand description
⚙️ Function: Extracts and returns League of Legends rank information.
This function processes rank data to extract key details such as tier, division, league points (LP), wins, losses, and winrate. The resulting information is formatted into a JSON-like value for use in other parts of the application, such as creating embeds for Discord.
§Parameters:
rank_data: A HashMap containing the player’s rank information, typically fetched from the Riot API. This data includes keys such as"tier","rank","leaguePoints","wins", and"losses".
§Returns:
Value: A JSON-like value containing the extracted rank information:tier: The rank tier (e.g., “Gold”, “Platinum”), defaults to “Unranked” if not present.division: The rank division (e.g., “I”, “II”), empty if not present.lp: League points, defaults to 0 if not present.wins: Number of wins, defaults to 0 if not present.losses: Number of losses, defaults to 0 if not present.winrate: The player’s winrate, calculated aswins / (wins + losses), defaults to 0 if no games are played.
§⚠️ Notes:
- If the player is unranked or data is missing, the function will return default values such as
"Unranked"for the tier, and0for LP, wins, and losses. - The winrate is calculated as a percentage and will return
0.0%if there are no games played (i.e., wins + losses = 0).
§Example:
let rank_data = some_function_fetching_rank_data();
let rank_info = extract_rank_info(&rank_data);The resulting rank_info will be in the following format:
{
"tier": "Gold",
"division": "II",
"lp": 45,
"wins": 20,
"losses": 15,
"winrate": 57.14
}