From e04e5d9b6f6340c48a8537f98cbd7a098f291788 Mon Sep 17 00:00:00 2001 From: Neil Armitage Date: Sat, 12 Feb 2022 22:33:35 +0200 Subject: [PATCH] Adding comments to team client --- src/clients/teams.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/clients/teams.ts b/src/clients/teams.ts index 9466707..a697c20 100644 --- a/src/clients/teams.ts +++ b/src/clients/teams.ts @@ -2,13 +2,27 @@ import IRequestClient, { IResponse } from '../interfaces/request'; import { ITeam, ITeamClient, ITeamMember } from '../interfaces/teams'; import { parse } from 'node-html-parser'; +/** + * Client for retrieving Team data specifically + * @class TeamClient + */ export class TeamClient implements ITeamClient { private requestClient: IRequestClient; + /** + * + * @param requestClient Create a new TeamClient + * @param requestClient Instance of a type of IRequestClient this will use to retrieve data from Liquipedia + */ constructor(requestClient: IRequestClient) { this.requestClient = requestClient; } + /** + * Get the details of a team by name + * @param teamName The name of the team as it would appear in a URL on Liquipedia + * @returns An object containing all team details from Liquipedia + */ public getTeam(teamName: string): Promise { return new Promise((resolve, reject) => { const encodedTeamName = teamName.replace(/ /g, '_'); @@ -23,6 +37,11 @@ export class TeamClient implements ITeamClient { }); } + /** + * Parses the HTML response from Liquipedia into an ITeam object + * @param response The response object from the Liquipedia server, containing the HTML to parse + * @returns An ITeam object populated with details parsed from the HTML + */ private _parseTeam(response: IResponse): ITeam { const htmlRoot = parse(response.parse.text['*']); @@ -68,6 +87,11 @@ export class TeamClient implements ITeamClient { }; } + /** + * Clean up the full name of a player to remove some parts that aren't needed + * @param fullName The full name value of the player + * @returns Cleaned up name with certain characters removed + */ private _cleanupName(fullName: string): string { const cleanedUp = /\((.+)\)/.exec(fullName); return cleanedUp ? cleanedUp[1] : fullName;