Created
July 3, 2021 04:51
-
-
Save ardydedase/1196af12cea3ddbf10501818511406f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Used for parsed car model info from the supported website. | |
| */ | |
| export class ModelParser { | |
| private modelInfo: string; | |
| constructor(modelInfo: string) { | |
| this.modelInfo = modelInfo; | |
| } | |
| /** | |
| * Parses the car's year from the string pattern: "{year} {make} {model}"" | |
| * @returns year | |
| */ | |
| getYear(): number { | |
| const regex = new RegExp(/\d{4}/g); | |
| let year; | |
| while ((year = regex.exec(this.modelInfo)) != null) { | |
| return Number(year[0]); | |
| } | |
| return 0; | |
| } | |
| /** | |
| * Parses the car's model from the string pattern: "{year} {make} {model}"" | |
| * This is different from the other getModel for supported cars list. | |
| * @returns model | |
| */ | |
| getModel(): string { | |
| const modelInfoArray = this.modelInfo.trim().split(" ").slice(2); | |
| return modelInfoArray.join(" "); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment