File indexing completed on 2024-12-29 04:51:04
0001 /* 0002 SPDX-FileCopyrightText: 2023 Volker Krause <vkrause@kde.org> 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 function parsePdfTicket(pdf, node, triggerNode) { 0007 const text = pdf.pages[triggerNode.location].text; 0008 let res = JsonLd.newBoatReservation(); 0009 const dep = text.match(/Departure: (.*) +(\d{2}\/\d{2}\/\d{2} \d{2}:\d{2})/); 0010 res.reservationFor.departureBoatTerminal.name = dep[1]; 0011 res.reservationFor.departureTime = JsonLd.toDateTime(dep[2], 'dd/MM/yy hh:mm', 'it'); 0012 const arr = text.match(/Arrival: (.*) +(\d{2}\/\d{2}\/\d{2} \d{2}:\d{2})/); 0013 res.reservationFor.arrivalBoatTerminal.name = arr[1]; 0014 res.reservationFor.arrivalTime = JsonLd.toDateTime(arr[2], 'dd/MM/yy hh:mm', 'it'); 0015 res.reservationNumber = triggerNode.content; 0016 res.reservedTicket.ticketToken = 'barcode128:' + triggerNode.content; 0017 0018 let idx = 0; 0019 let reservations = [res]; 0020 let tokenPrefix = 10001; 0021 while (true) { 0022 const pas = text.substr(idx).match(/ +(\S.*\S) +[MF] +\d\d-\d\d-\d{4}\n/); 0023 if (!pas) 0024 break; 0025 idx += pas.index + pas[0].length; 0026 let r = JsonLd.clone(res); 0027 const name = pas[1].split(/ +/); 0028 r.underName.familyName = name[0]; 0029 r.underName.givenName = name[1]; 0030 r.reservedTicket.ticketToken = 'ean13:' + tokenPrefix++ + triggerNode.content.substr(3); 0031 reservations.push(r); 0032 } 0033 return reservations; 0034 }