KItinerary

iatabcbpdocumentprocessor.cpp
1/*
2 SPDX-FileCopyrightText: 2021 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "iatabcbpdocumentprocessor.h"
8
9#include "iata/iatabcbp.h"
10#include "iata/iatabcbpparser.h"
11
12#include <KItinerary/ExtractorResult>
13
14using namespace KItinerary;
15
16bool IataBcbpDocumentProcessor::canHandleData(const QByteArray &encodedData, [[maybe_unused]] QStringView fileName) const
17{
18 return IataBcbp::maybeIataBcbp(encodedData);
19}
20
22{
24 IataBcbp ticket(QString::fromUtf8(encodedData));
25 if (ticket.isValid()) {
26 node.setContent(ticket);
27 }
28 return node;
29}
30
31void IataBcbpDocumentProcessor::preExtract(ExtractorDocumentNode &node, [[maybe_unused]] const ExtractorEngine *engine) const
32{
33 const auto bcbp = node.content<IataBcbp>();
35}
36
38{
39 const auto bcbp = node.content<IataBcbp>();
40 const auto ums = bcbp.uniqueMandatorySection();
41 const auto ucs = bcbp.uniqueConditionalSection();
42 if (matchesGadget(filter, &ums) || matchesGadget(filter, &ucs)) {
43 return true;
44 }
45 const auto legCount = ums.numberOfLegs();
46 for (int i = 0; i < legCount; ++i) {
47 const auto rms = bcbp.repeatedMandatorySection(i);
48 const auto rcs = bcbp.repeatedConditionalSection(i);
49 if (matchesGadget(filter, &rms) || matchesGadget(filter, &rcs)) {
50 return true;
51 }
52 }
53 return false;
54}
A node in the extracted document object tree.
QJSValue content
The decoded content of this node.
void addResult(ExtractorResult &&result)
Add additional results from an extraction step.
QDateTime contextDateTime
The best known context date/time at this point in the document tree.
void setContent(const QVariant &content)
Set decoded content.
Semantic data extraction engine.
Determines whether an extractor is applicable to a given email.
bool canHandleData(const QByteArray &encodedData, QStringView fileName) const override
Fast check whether the given encoded data can possibly be processed by this instance.
void preExtract(ExtractorDocumentNode &node, const ExtractorEngine *engine) const override
Called before extractors are applied to node.
ExtractorDocumentNode createNodeFromData(const QByteArray &encodedData) const override
Create a document node from raw data.
bool matches(const ExtractorFilter &filter, const ExtractorDocumentNode &node) const override
Checks whether the given filter matches node.
A IATA BarCoded Boarding Pass (BCBP)
Definition iatabcbp.h:21
static bool maybeIataBcbp(const QByteArray &data)
Fast checks whether this might be an IATA BCBP.
Definition iatabcbp.cpp:146
QList< QVariant > parse(const QString &message, const QDateTime &externalIssueDateTime=QDateTime())
Parses the bar coded boarding pass message message into a list of FlightReservation instances.
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
QString fromUtf8(QByteArrayView str)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:45:38 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.