All files / Scripts Summary.ts

90% Statements 36/40
83.33% Branches 15/18
90% Functions 9/10
91.17% Lines 31/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 753x 3x 3x     3x 3x   3x 41x 41x 41x 41x     31x 31x           41x   41x   41x                         368x 46x       34x         272x 34x 13x 13x     21x     187x     31x 31x       11x 11x 11x 88x   11x      
import { mhaStrings } from "./mhaStrings";
import { ArchivedRow } from "./row/ArchivedRow";
import { CreationRow } from "./row/CreationRow";
import { Header } from "./row/Header";
import { Row } from "./row/Row";
import { SummaryRow } from "./row/SummaryRow";
import { SummaryTable } from "./table/SummaryTable";
 
export class Summary extends SummaryTable {
    public readonly tableName: string = "summary";
    public readonly displayName: string = mhaStrings.mhaSummary;
    public readonly tag: string = "SUM";
    private totalTimeInternal = "";
 
    private creationPostFix(totalTime: string): string {
        Eif (!totalTime) {
            return "";
        }
 
        return ` ${mhaStrings.mhaDeliveredStart} ${totalTime}${mhaStrings.mhaDeliveredEnd}`;
    }
 
    private dateRow = new CreationRow("Date", mhaStrings.mhaCreationTime);
 
    private archivedRow = new ArchivedRow("Archived-At", mhaStrings.mhaArchivedAt,);
 
    private summaryRows: SummaryRow[] = [
        new SummaryRow("Subject", mhaStrings.mhaSubject),
        new SummaryRow("Message-ID", mhaStrings.mhaMessageId),
        this.archivedRow,
        this.dateRow,
        new SummaryRow("From", mhaStrings.mhaFrom),
        new SummaryRow("Reply-To", mhaStrings.mhaReplyTo),
        new SummaryRow("To", mhaStrings.mhaTo),
        new SummaryRow("CC", mhaStrings.mhaCc)
    ];
 
    public override exists(): boolean {
        let row: Row | undefined;
        this.rows.forEach((r: Row) => { if (!row && r.value) row = r; });
        return row !== undefined;
    }
 
    public add(header: Header) {
        Iif (!header) {
            return false;
        }
 
        let row: SummaryRow | undefined;
        this.rows.forEach((r: Row) => { if (!row && r.header.toUpperCase() === header.header.toUpperCase()) row = r; });
        if (row) {
            row.value = header.value;
            return true;
        }
 
        return false;
    }
 
    public get rows(): SummaryRow[] { return this.summaryRows; }
    public get totalTime(): string { return this.totalTimeInternal; }
    public set totalTime(value: string) {
        this.totalTimeInternal = value;
        this.dateRow.postFix = this.creationPostFix(value);
    }
 
    public override toString(): string {
        Iif (!this.exists()) return "";
        const ret = ["Summary"];
        this.rows.forEach(function (row) {
            if (row.value) { ret.push(row.toString()); }
        });
        return ret.join("\n");
    }
}