Advertisement
Guest User

MatchReader

a guest
Aug 24th, 2021
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. abstract class CsvFileReader<T> {
  2.   data: T[] = []
  3.  
  4.   constructor(public file: string) {}
  5.  
  6.   abstract mapRow(row: string[]): T
  7.  
  8.   read() {
  9.     this.data = this.file
  10.       .split('\n')
  11.       .map((row: string): string[] => {
  12.         return row.split(',')
  13.       })
  14.       .map(this.mapRow)
  15.   }
  16. }
  17.  
  18. type matchData = [string, string, string, number, number, string]
  19.  
  20. class MatchReader extends CsvFileReader<matchData> {
  21.   mapRow(row: string[]): matchData {
  22.     return [
  23.       row[0],
  24.       row[1],
  25.       row[2],
  26.       +row[3],
  27.       +row[4],
  28.       row[6],
  29.     ]
  30.   }
  31. }
  32.  
  33. const reader = new MatchReader("a,b,c,15,7,-,X");
  34. reader.read();
  35. console.log(reader);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement