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

0001 /*
0002    SPDX-FileCopyrightText: 2022 Robin Grindrod <robingrindrod@live.ie>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 function main(html) {
0008     var res = JsonLd.newLodgingReservation();
0009 
0010     res.reservationNumber = html.eval('//div[@class="refnum"]/p')[0].recursiveContent;
0011 
0012     var times = html.eval('/html/body/table/tr/td/table/tr/td/div/div/div/div/table/tr/td/table/tr/td/div/p/b');
0013     res.checkinTime = JsonLd.toDateTime(times[0].recursiveContent.replace(/\s+/g, ' '), "'From' ha - ddd dd MMM yyyy", 'en');
0014     res.checkoutTime = JsonLd.toDateTime(times[1].recursiveContent.replace(/\s+/g, ' '), "'Before' ha - ddd dd MMM yyyy", 'en');
0015 
0016     var hotelName = html.eval('/html/body/table/tr/td/table/tr/td/div/div/div/div/table/tr/td/table/tr/td/div/h2')[0].recursiveContent;
0017     res.reservationFor.name = 'Premier Inn ' + hotelName;
0018 
0019     // This works for the example I have. I'm not sure how brittle it will be
0020     // with other examples
0021     var address = html.eval('/html/body/table/tr/td/table/tr/td/div/div/div/div/table/tr/td/table/tr/td/div/table/tbody/tr/td')[1].recursiveContent.split(', ');
0022     res.reservationFor.address.streetAddress = address[0];
0023     res.reservationFor.address.addressLocality = address[1];
0024     res.reservationFor.address.addressRegion = address[2];
0025     res.reservationFor.address.addressCountry = address[3];
0026     res.reservationFor.address.postalCode = address[4];
0027 
0028     res.underName.name = html.eval('/html/body/table/tr/td/table/tr/td/div/div/div/div/div/table/tr/td/table/tr/td/div/p')[0].recursiveContent.split('\n')[0];
0029     
0030     return res;
0031 }