import { BoutsGetter , BoutsInterface } from "../../decorators/bouts.decorator" ; import { OutputGetter , OutputInterface } from "../../decorators/output.decorator" ; import { replaceWithWeight , trimRemoveLineBreaks } from "../../helpers" ; import { BoxrecBasic } from "../boxrec.constants" ; import { BoxrecParseBouts } from "../event/boxrec.parse.bouts" ; import { BoxrecPageTitlesRow } from "../titles/boxrec.page.titles.row" ; import { BoxrecTitleOutput } from "./boxrec.page.title.constants" ; import { BoxrecPageTitleRow } from "./boxrec.page.title.row" ; /**
 * parse a BoxRec Title page
 * <pre>ex. http://boxrec.com/en/title/6/Middleweight
 */ @ BoutsGetter ( "table" , BoxrecPageTitlesRow ) @ OutputGetter ( [ { function : ( bouts ) => bouts . map ( bout => bout . output ) , method : "bouts" , } , "champion" , "name" , "numberOfBouts" , ] ) export class BoxrecPageTitle extends BoxrecParseBouts implements BoutsInterface , OutputInterface { returns { BoxrecPageTitleRow [ ] } bouts : BoxrecPageTitlesRow [ ] ; output : BoxrecTitleOutput ; returns { number } get numberOfBouts ( ) : number { return parseInt ( this . $ ( ".pagerResults" ) . text ( ) , 10 ) ; } returns { BoxrecBasic } get champion ( ) : BoxrecBasic { const championStr = this . $ ( "#pageOuter h2" ) . html ( ) ; const html = this . $ ( `<div>${ championStr }</div>` ) ; const boxerLink = html . find ( "a" ) ; if ( boxerLink ) { const link = boxerLink . get ( 0 ) ; const href = link . attribs . href . match ( /(\d+)$/ ) ; if ( href && href [ 1 ] ) { return { id : parseInt ( href [ 1 ] , 10 ) , name : trimRemoveLineBreaks ( html . text ( ) ) , } ; } } return { id : null , name : null , } ; } get name ( ) : string { return replaceWithWeight ( this . $ ( "#pageOuter h1" ) . text ( ) ) ; } }