import { BoxrecPageLists } from "../../boxrec-common-tables/boxrec-page-lists" ; import { OutputGetter , OutputInterface } from "../../decorators/output.decorator" ; import { getHeaderColumnText , trimRemoveLineBreaks } from "../../helpers" ; import { BoxrecPageRatingsActiveAllDivisionsRow } from "./boxrec.page.ratings.active-all-divisions.row" ; import { BoxrecPageRatingsActiveDivisionRow } from "./boxrec.page.ratings.active-division.row" ; import { BoxrecPageRatingsActiveInactiveAllDivisionsRow } from "./boxrec.page.ratings.active-inactive-all-divisions.row" ; import { BoxrecPageRatingsActiveInactiveDivisionRow } from "./boxrec.page.ratings.active-inactive-division.row" ; import { BoxrecRatingsOutput } from "./boxrec.ratings.constants" ; enum BoxrecRatingsType { activeAllDivisions , activeWeightDivision , activeInactiveAllDivisions , activeInactiveWeightDivision } const ratingsTableEl = "#ratingsResults" ; /**
 * parse a BoxRec Ratings Page
 * <pre>ex. http://boxrec.com/en/ratings</pre>
 */ @ OutputGetter ( [ { function : ( boxers ) => boxers . map ( boxerRow => boxerRow . output ) , method : "boxers" , } , "numberOfPages" ] ) export class BoxrecPageRatings extends BoxrecPageLists implements OutputInterface { output : BoxrecRatingsOutput ; get boxers ( ) : Array < BoxrecPageRatingsActiveDivisionRow | BoxrecPageRatingsActiveInactiveAllDivisionsRow | BoxrecPageRatingsActiveAllDivisionsRow | BoxrecPageRatingsActiveInactiveDivisionRow > { const headerColumns = getHeaderColumnText ( this . $ ( ratingsTableEl ) ) ; return this . parseRatingsTableContent ( ) . map ( item => { switch ( this . getRatingsType ( ) ) { case BoxrecRatingsType . activeWeightDivision : return new BoxrecPageRatingsActiveDivisionRow ( headerColumns , item ) ; case BoxrecRatingsType . activeInactiveAllDivisions : return new BoxrecPageRatingsActiveInactiveAllDivisionsRow ( headerColumns , item ) ; case BoxrecRatingsType . activeAllDivisions : return new BoxrecPageRatingsActiveAllDivisionsRow ( headerColumns , item ) ; case BoxrecRatingsType . activeInactiveWeightDivision : return new BoxrecPageRatingsActiveInactiveDivisionRow ( headerColumns , item ) ; } } ) ; } /**
     * Returns the HTML content of table rows
     */ private parseRatingsTableContent ( ) { return this . $ ( ratingsTableEl ) . find ( "tbody tr" ) . filter ( ( index , tableRow ) => { return this . $ ( tableRow ) . find ( "td" ) . length > 6 ; } ) . map ( ( i , elem ) => this . $ ( elem ) . html ( ) ) . get ( ) ; } private getRatingsType ( ) { const numberOfColumns = this . $ ( ratingsTableEl ) . find ( "tbody tr:nth-child(1) td" ) . length ; if ( numberOfColumns === 9 ) { const headerText = trimRemoveLineBreaks ( this . $ ( ratingsTableEl ) . find ( "thead th:nth-child(6)" ) . text ( ) ) ; if ( headerText === "career" ) { return BoxrecRatingsType . activeInactiveAllDivisions ; } else { return BoxrecRatingsType . activeWeightDivision ; } } else if ( numberOfColumns === 10 ) { return BoxrecRatingsType . activeAllDivisions ; } else if ( numberOfColumns === 8 ) { return BoxrecRatingsType . activeInactiveWeightDivision ; } throw new Error ( `Unknown number of columns,
 has something changed on BoxRec ratings? numberOfColumns: ${ numberOfColumns }` ) ; } }