import * as cheerio from "cheerio" ; import { OutputGetter , OutputInterface } from "../../decorators/output.decorator" ; import { BoxrecPageWatchRow } from "./boxrec.page.watch.row" ; import { BoxrecWatchOutput } from "./boxrec.watch.constants" ; @ OutputGetter ( [ { function : ( list ) => list . map ( item => item . output ) , method : "list" } ] ) export class BoxrecPageWatch implements OutputInterface { output : BoxrecWatchOutput ; private readonly $ : CheerioStatic ; constructor ( boxrecBodyString ) { this . $ = cheerio . load ( boxrecBodyString ) ; } get list ( ) : BoxrecPageWatchRow [ ] { const listOfWatchedBoxers = [ ] ; this . $ ( "table tr" ) . each ( ( i , elem ) => { const html = this . $ ( elem ) . html ( ) || "" ; if ( ! html . includes ( "<th>" ) ) { const boxerRow = new BoxrecPageWatchRow ( html ) ; if ( boxerRow . globalId ) { listOfWatchedBoxers . push ( new BoxrecPageWatchRow ( html ) ) ; } } } ) ; return listOfWatchedBoxers ; } param { number } boxerGlobalId returns { boolean } checkForBoxerInList ( boxerGlobalId ) { return ! ! this . list . find ( ( item ) => item . globalId === boxerGlobalId ) ; } }