-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbankFactory.cpp
More file actions
executable file
·84 lines (75 loc) · 2.63 KB
/
Copy pathbankFactory.cpp
File metadata and controls
executable file
·84 lines (75 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "bankFactory.h"
#include "bank.h"
#include <QDebug>
#include <QHash>
#include "banks/bice.h"
#include "banks/chile.h"
#include "banks/estado.h"
#include "banks/santander.h"
// #include "banks/wise.h"
namespace pdfparser {
std::unique_ptr<Bank> BankFactory::create(BankType type,
const QString &typeAccount)
{
switch (type) {
case BankType::BICE:
return std::make_unique<BICE>(typeAccount);
case BankType::CHILE:
return std::make_unique<Chile>(typeAccount);
case BankType::SANTANDER:
return std::make_unique<Santander>(typeAccount);
case BankType::ESTADO:
return std::make_unique<Estado>(typeAccount);
// case BankType::WISE:
// return std::make_unique<Wise>(typeAccount);
case BankType::WISE:
case BankType::UNKNOWN:
default:
qDebug() << "Tipo de banco no soportado";
return nullptr;
}
}
std::unique_ptr<Bank> BankFactory::create(const QString &bankName,
const QString &typeAccount)
{
const BankType type = fromString(bankName);
if (type == BankType::UNKNOWN) {
qDebug() << "Banco no soportado:" << bankName;
return nullptr;
}
return create(type, typeAccount);
}
std::unique_ptr<Bank> BankFactory::create(const QString &bankName,
const QString &typeAccount,
const QString &filePath)
{
auto bank = create(bankName, typeAccount);
if (bank)
bank->filePath = filePath;
return bank;
}
BankFactory::BankType BankFactory::fromString(const QString &bankName)
{
// Keyword scan: the parent app may pass arbitrary text such as
// "Banco de Chile - Cuenta Corriente" or "Santander Chile, abril".
// We match the FIRST keyword that appears in the input, preferring
// longer keywords so "Santander Chile" resolves to SANTANDER (the
// entity) rather than CHILE.
struct Keyword { const char *needle; BankType type; };
static const Keyword keywords[] = {
// Order: longest first → prevents short keywords from shadowing
// longer entity names that contain them.
{ "santander", BankType::SANTANDER },
{ "estado", BankType::ESTADO },
{ "chile", BankType::CHILE },
{ "bice", BankType::BICE },
{ "wise", BankType::WISE },
};
const QString hay = bankName.toLower();
for (const auto &kw : keywords) {
if (hay.contains(QLatin1String(kw.needle)))
return kw.type;
}
return BankType::UNKNOWN;
}
} // namespace pdfparser