File indexing completed on 2024-12-29 04:51:04

0001 /*
0002    SPDX-FileCopyrightText: 2022 Volker Krause <vkrause@kde.org>
0003    SPDX-License-Identifier: LGPL-2.0-or-later
0004 */
0005 
0006 function parseTicket(content, node, triggerNode) {
0007     const text = content.pages[triggerNode.location].text;
0008     let res = JsonLd.newTrainReservation();
0009     res.reservedTicket.ticketToken = 'azteccode:' + triggerNode.content;
0010     res.reservationNumber = text.match(/  ([A-Z0-9]{6})  /)[1];
0011     const dt = text.match(/ (\d\d\/\d\d) /)[1];
0012     const leg = text.match(/Treno: (\d+) (\d\d:\d\d) (.*?) → (\d\d:\d\d) (.*)\n/);
0013     res.reservationFor.departureStation.name = leg[3];
0014     res.reservationFor.departureTime = JsonLd.toDateTime(dt + ' ' + leg[2], 'dd/MM hh:mm', 'en');
0015     res.reservationFor.arrivalStation.name = leg[5];
0016     res.reservationFor.arrivalTime = JsonLd.toDateTime(dt + ' ' + leg[4], 'dd/MM hh:mm', 'en');
0017     res.reservationFor.trainNumber = leg[1];
0018 
0019     let idx = 0;
0020     let reservations = [];
0021     while (true) {
0022         let pas = text.substr(idx).match(/ +\d\. (.*)  +Voiture (\d+) Place (\d+)\n/);
0023         if (!pas) {
0024             break;
0025         }
0026         let r = JsonLd.clone(res);
0027         r.underName.name = pas[1];
0028         r.reservedTicket.ticketedSeat.seatSection = pas[2];
0029         r.reservedTicket.ticketedSeat.seatNumber = pas[3];
0030         reservations.push(r);
0031         idx += pas.index + pas[0].length;
0032     }
0033 
0034     return reservations.length > 0 ? reservations : res;
0035 }