mindee
Version:
Mindee Client Library for Node.js
119 lines (118 loc) • 5.16 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 _BillOfLadingV1CarrierItem_instances, _BillOfLadingV1CarrierItem_printableValues;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BillOfLadingV1CarrierItem = void 0;
const common_1 = require("../../parsing/common");
const geometry_1 = require("../../geometry");
/**
* The goods being shipped.
*/
class BillOfLadingV1CarrierItem {
constructor({ prediction = {} }) {
_BillOfLadingV1CarrierItem_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"];
if (prediction["gross_weight"] !== undefined &&
prediction["gross_weight"] !== null &&
!isNaN(prediction["gross_weight"])) {
this.grossWeight = +parseFloat(prediction["gross_weight"]);
}
else {
this.grossWeight = null;
}
if (prediction["measurement"] !== undefined &&
prediction["measurement"] !== null &&
!isNaN(prediction["measurement"])) {
this.measurement = +parseFloat(prediction["measurement"]);
}
else {
this.measurement = null;
}
this.measurementUnit = prediction["measurement_unit"];
if (prediction["quantity"] !== undefined &&
prediction["quantity"] !== null &&
!isNaN(prediction["quantity"])) {
this.quantity = +parseFloat(prediction["quantity"]);
}
else {
this.quantity = null;
}
this.weightUnit = prediction["weight_unit"];
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, _BillOfLadingV1CarrierItem_instances, "m", _BillOfLadingV1CarrierItem_printableValues).call(this);
return ("Description: " +
printable.description +
", Gross Weight: " +
printable.grossWeight +
", Measurement: " +
printable.measurement +
", Measurement Unit: " +
printable.measurementUnit +
", Quantity: " +
printable.quantity +
", Weight Unit: " +
printable.weightUnit);
}
/**
* Output in a format suitable for inclusion in an rST table.
*/
toTableLine() {
const printable = __classPrivateFieldGet(this, _BillOfLadingV1CarrierItem_instances, "m", _BillOfLadingV1CarrierItem_printableValues).call(this);
return ("| " +
printable.description.padEnd(36) +
" | " +
printable.grossWeight.padEnd(12) +
" | " +
printable.measurement.padEnd(11) +
" | " +
printable.measurementUnit.padEnd(16) +
" | " +
printable.quantity.padEnd(8) +
" | " +
printable.weightUnit.padEnd(11) +
" |");
}
}
exports.BillOfLadingV1CarrierItem = BillOfLadingV1CarrierItem;
_BillOfLadingV1CarrierItem_instances = new WeakSet(), _BillOfLadingV1CarrierItem_printableValues = function _BillOfLadingV1CarrierItem_printableValues() {
return {
description: this.description ?
this.description.length <= 36 ?
(0, common_1.cleanSpecialChars)(this.description) :
(0, common_1.cleanSpecialChars)(this.description).slice(0, 33) + "..." :
"",
grossWeight: this.grossWeight !== undefined ? (0, common_1.floatToString)(this.grossWeight) : "",
measurement: this.measurement !== undefined ? (0, common_1.floatToString)(this.measurement) : "",
measurementUnit: this.measurementUnit ?
this.measurementUnit.length <= 16 ?
(0, common_1.cleanSpecialChars)(this.measurementUnit) :
(0, common_1.cleanSpecialChars)(this.measurementUnit).slice(0, 13) + "..." :
"",
quantity: this.quantity !== undefined ? (0, common_1.floatToString)(this.quantity) : "",
weightUnit: this.weightUnit ?
this.weightUnit.length <= 11 ?
(0, common_1.cleanSpecialChars)(this.weightUnit) :
(0, common_1.cleanSpecialChars)(this.weightUnit).slice(0, 8) + "..." :
"",
};
};