Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: change finance class to namespace #742

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 27 additions & 29 deletions include/faker-cxx/Finance.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@
#include "types/Country.h"
#include "types/Precision.h"

namespace faker
namespace faker::finance
{
struct Currency
{
std::string_view name;
std::string_view code;
std::string_view symbol;
};
struct Currency
{
std::string_view name;
std::string_view code;
std::string_view symbol;
};


class Finance
{
public:
/**
* @brief Returns a random currency.
*
Expand All @@ -28,7 +26,7 @@ class Finance
* Finance::currency() // "{"US Dollar","USD","$"}"
* @endcode
*/
static Currency currency();
Currency currency();

/**
* @brief Returns a random currency name.
Expand All @@ -39,7 +37,7 @@ class Finance
* Finance::currencyName() // "US Dollar"
* @endcode
*/
static std::string_view currencyName();
std::string_view currencyName();

/**
* @brief Returns a random currency code.
Expand All @@ -50,7 +48,7 @@ class Finance
* Finance::currencyCode() // "USD"
* @endcode
*/
static std::string_view currencyCode();
std::string_view currencyCode();

/**
* @brief Returns a random currency symbol.
Expand All @@ -61,7 +59,7 @@ class Finance
* Finance::currencySymbol() // "$"
* @endcode
*/
static std::string_view currencySymbol();
std::string_view currencySymbol();

/**
* @brief Returns a random account type.
Expand All @@ -72,7 +70,7 @@ class Finance
* Finance::accountType() // "Savings"
* @endcode
*/
static std::string_view accountType();
std::string_view accountType();

/**
* @brief Generates a random amount between the given bounds (inclusive).
Expand All @@ -91,7 +89,7 @@ class Finance
* Finance::amount(5, 10, Precision::TwoDp, "$") // "$5.85"
* @endcode
*/
static std::string amount(double min = 0, double max = 1000, Precision precision = Precision::TwoDp,
std::string amount(double min = 0, double max = 1000, Precision precision = Precision::TwoDp,
const std::string& symbol = "");

enum class IbanCountry
Expand Down Expand Up @@ -137,7 +135,7 @@ class Finance
* Finance::iban(IbanCountry::Poland) // "PL61109010140000071219812874"
* @endcode
*/
static std::string iban(std::optional<IbanCountry> country = std::nullopt);
std::string iban(std::optional<IbanCountry> country = std::nullopt);

enum class BicCountry
{
Expand Down Expand Up @@ -165,7 +163,7 @@ class Finance
* Finance::bic(BicCountry::Poland) // "BREXPLPWMUL"
* @endcode
*/
static std::string_view bic(std::optional<BicCountry> country = std::nullopt);
std::string_view bic(std::optional<BicCountry> country = std::nullopt);

/**
* Generates a random account number.
Expand All @@ -179,7 +177,7 @@ class Finance
* Finance::accountNumber(26) // "55875455514825927518796290"
* @endcode
*/
static std::string accountNumber(unsigned length = 8);
std::string accountNumber(unsigned length = 8);

/**
* Generates a random PIN number.
Expand All @@ -193,7 +191,7 @@ class Finance
* Finance::pin(8) // "21378928"
* @endcode
*/
static std::string pin(unsigned length = 4);
std::string pin(unsigned length = 4);

/**
* Generates a random routing number.
Expand All @@ -204,7 +202,7 @@ class Finance
* Finance::routingNumber() // "522814402"
* @endcode
*/
static std::string routingNumber();
std::string routingNumber();

enum class CreditCardType
{
Expand All @@ -225,7 +223,7 @@ class Finance
* Finance::creditCardNumber() // "4882664999007"
* @endcode
*/
static std::string creditCardNumber(std::optional<CreditCardType> creditCardType = std::nullopt);
std::string creditCardNumber(std::optional<CreditCardType> creditCardType = std::nullopt);

/**
* Generates a random credit card CVV.
Expand All @@ -236,7 +234,7 @@ class Finance
* Finance::creditCardCvv() // "506"
* @endcode
*/
static std::string creditCardCvv();
std::string creditCardCvv();

/**
* Generates a random bitcoin address.
Expand All @@ -247,7 +245,7 @@ class Finance
* Finance::bitcoinAddress() // "3ySdvCkTLVy7gKD4j6JfSaf5d"
* @endcode
*/
static std::string bitcoinAddress();
std::string bitcoinAddress();

/**
* Generates a random litecoin address.
Expand All @@ -258,7 +256,7 @@ class Finance
* Finance::litecoinAddress() // "LoQaSTGWBRXkWfyxKbNKuPrAWGELzcW"
* @endcode
*/
static std::string litecoinAddress();
std::string litecoinAddress();

/**
* Generates a random ethereum address.
Expand All @@ -269,7 +267,7 @@ class Finance
* Finance::ethereumAddress() // "0xf03dfeecbafc5147241cc4c4ca20b3c9dfd04c4a"
* @endcode
*/
static std::string ethereumAddress();
std::string ethereumAddress();

/**
* Generates a random expiration date.
Expand All @@ -280,7 +278,7 @@ class Finance
* Finance::creditCardExpirationDate() // "03/26"
* @endcode
*/
static std::string creditCardExpirationDate();
std::string creditCardExpirationDate();

/**
* Generates a random credit card type.
Expand All @@ -291,6 +289,6 @@ class Finance
* Finance::creditCardType() // "Visa"
* @endcode
*/
static std::string_view creditCardType();
};
std::string_view creditCardType();

}
39 changes: 20 additions & 19 deletions src/modules/finance/Finance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,36 @@
#include "faker-cxx/types/Precision.h"
#include "FinanceData.h"

namespace faker

namespace faker::finance
{

Currency Finance::currency()
Currency currency()
{
return Helper::arrayElement(currencies);
}

std::string_view Finance::currencyName()
std::string_view currencyName()
{
return Helper::arrayElement(currencies).name;
}

std::string_view Finance::currencyCode()
std::string_view currencyCode()
{
return Helper::arrayElement(currencies).code;
}

std::string_view Finance::currencySymbol()
std::string_view currencySymbol()
{
return Helper::arrayElement(currencies).symbol;
}

std::string_view Finance::accountType()
std::string_view accountType()
{
return Helper::arrayElement(accountTypes);
}

std::string Finance::amount(double min, double max, Precision precision, const std::string& symbol)
std::string amount(double min, double max, Precision precision, const std::string& symbol)
{
const std::floating_point auto generatedNumber = number::decimal<double>(min, max);

Expand All @@ -53,7 +54,7 @@ std::string Finance::amount(double min, double max, Precision precision, const s
return result;
}

std::string Finance::iban(std::optional<Finance::IbanCountry> country)
std::string iban(std::optional<IbanCountry> country)
{
const auto ibanCountry = country ? *country : Helper::arrayElement(ibanCountries);

Expand Down Expand Up @@ -88,29 +89,29 @@ std::string Finance::iban(std::optional<Finance::IbanCountry> country)
return iban;
}

std::string_view Finance::bic(std::optional<Finance::BicCountry> country)
std::string_view bic(std::optional<BicCountry> country)
{
const auto bicCountry = country ? *country : Helper::arrayElement(bicCountries);

return Helper::arrayElement(bicCountriesCodes.at(bicCountry));
}

std::string Finance::accountNumber(unsigned int length)
std::string accountNumber(unsigned int length)
{
return String::numeric(length, true);
}

std::string Finance::pin(unsigned int length)
std::string pin(unsigned int length)
{
return String::numeric(length, true);
}

std::string Finance::routingNumber()
std::string routingNumber()
{
return String::numeric(9, true);
}

std::string Finance::creditCardNumber(std::optional<Finance::CreditCardType> creditCardType)
std::string creditCardNumber(std::optional<CreditCardType> creditCardType)
{
const auto creditCardTargetType = creditCardType ? *creditCardType : Helper::arrayElement(creditCardTypes);

Expand All @@ -132,12 +133,12 @@ std::string Finance::creditCardNumber(std::optional<Finance::CreditCardType> cre
return "";
}

std::string Finance::creditCardCvv()
std::string creditCardCvv()
{
return String::numeric(3, true);
}

std::string Finance::bitcoinAddress()
std::string bitcoinAddress()
{
const unsigned addressLength = number::integer(26u, 33u);

Expand All @@ -148,7 +149,7 @@ std::string Finance::bitcoinAddress()
return address;
}

std::string Finance::litecoinAddress()
std::string litecoinAddress()
{
const unsigned addressLength = number::integer(26u, 33u);

Expand All @@ -159,19 +160,19 @@ std::string Finance::litecoinAddress()
return address;
}

std::string Finance::ethereumAddress()
std::string ethereumAddress()
{
return String::hexadecimal(40, HexCasing::Lower);
}

std::string Finance::creditCardExpirationDate()
std::string creditCardExpirationDate()
{
const auto expirationDate = faker::date::futureDate(3);

return expirationDate.substr(5, 2) + "/" + expirationDate.substr(2, 2);
}

std::string_view Finance::creditCardType()
std::string_view creditCardType()
{
return Helper::arrayElement(creditCardNames);
}
Expand Down
Loading
Loading