mindee
Version:
Mindee Client Library for Node.js
119 lines (118 loc) • 5.08 kB
JavaScript
"use strict";
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
};
var _EnergyBillV1TaxesAndContribution_instances, _EnergyBillV1TaxesAndContribution_printableValues;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EnergyBillV1TaxesAndContribution = void 0;
const common_1 = require("../../../parsing/common");
const geometry_1 = require("../../../geometry");
/**
* Details of Taxes and Contributions.
*/
class EnergyBillV1TaxesAndContribution {
constructor({ prediction = {} }) {
_EnergyBillV1TaxesAndContribution_instances.add(this);
/** Confidence score */
this.confidence = 0.0;
/**
* Contains the relative vertices coordinates (points) of a polygon containing
* the field in the document.
*/
this.polygon = new geometry_1.Polygon();
this.description = prediction["description"];
this.endDate = prediction["end_date"];
this.startDate = prediction["start_date"];
if (prediction["tax_rate"] !== undefined &&
prediction["tax_rate"] !== null &&
!isNaN(prediction["tax_rate"])) {
this.taxRate = +parseFloat(prediction["tax_rate"]);
}
else {
this.taxRate = null;
}
if (prediction["total"] !== undefined &&
prediction["total"] !== null &&
!isNaN(prediction["total"])) {
this.total = +parseFloat(prediction["total"]);
}
else {
this.total = null;
}
if (prediction["unit_price"] !== undefined &&
prediction["unit_price"] !== null &&
!isNaN(prediction["unit_price"])) {
this.unitPrice = +parseFloat(prediction["unit_price"]);
}
else {
this.unitPrice = null;
}
this.pageId = prediction["page_id"];
this.confidence = prediction["confidence"] ? prediction.confidence : 0.0;
if (prediction["polygon"]) {
this.polygon = prediction.polygon;
}
}
/**
* Default string representation.
*/
toString() {
const printable = __classPrivateFieldGet(this, _EnergyBillV1TaxesAndContribution_instances, "m", _EnergyBillV1TaxesAndContribution_printableValues).call(this);
return ("Description: " +
printable.description +
", End Date: " +
printable.endDate +
", Start Date: " +
printable.startDate +
", Tax Rate: " +
printable.taxRate +
", Total: " +
printable.total +
", Unit Price: " +
printable.unitPrice);
}
/**
* Output in a format suitable for inclusion in an rST table.
*/
toTableLine() {
const printable = __classPrivateFieldGet(this, _EnergyBillV1TaxesAndContribution_instances, "m", _EnergyBillV1TaxesAndContribution_printableValues).call(this);
return ("| " +
printable.description.padEnd(36) +
" | " +
printable.endDate.padEnd(10) +
" | " +
printable.startDate.padEnd(10) +
" | " +
printable.taxRate.padEnd(8) +
" | " +
printable.total.padEnd(9) +
" | " +
printable.unitPrice.padEnd(10) +
" |");
}
}
exports.EnergyBillV1TaxesAndContribution = EnergyBillV1TaxesAndContribution;
_EnergyBillV1TaxesAndContribution_instances = new WeakSet(), _EnergyBillV1TaxesAndContribution_printableValues = function _EnergyBillV1TaxesAndContribution_printableValues() {
return {
description: this.description ?
this.description.length <= 36 ?
(0, common_1.cleanSpecialChars)(this.description) :
(0, common_1.cleanSpecialChars)(this.description).slice(0, 33) + "..." :
"",
endDate: this.endDate ?
this.endDate.length <= 10 ?
(0, common_1.cleanSpecialChars)(this.endDate) :
(0, common_1.cleanSpecialChars)(this.endDate).slice(0, 7) + "..." :
"",
startDate: this.startDate ?
this.startDate.length <= 10 ?
(0, common_1.cleanSpecialChars)(this.startDate) :
(0, common_1.cleanSpecialChars)(this.startDate).slice(0, 7) + "..." :
"",
taxRate: this.taxRate !== undefined ? (0, common_1.floatToString)(this.taxRate) : "",
total: this.total !== undefined ? (0, common_1.floatToString)(this.total) : "",
unitPrice: this.unitPrice !== undefined ? (0, common_1.floatToString)(this.unitPrice) : "",
};
};