Skip to content

Commit

Permalink
refactor: person module (#744)
Browse files Browse the repository at this point in the history
- person module migration from class to functions within person namespace

- modified reference to functions and variables from person module in all dependent modules

Signed-off-by: Guru Mehar Rachaputi <[email protected]>
  • Loading branch information
00thirdeye00 authored Jun 27, 2024
1 parent ac53456 commit d725fc7
Show file tree
Hide file tree
Showing 12 changed files with 277 additions and 277 deletions.
14 changes: 7 additions & 7 deletions examples/person/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@
#include "faker-cxx/Person.h"

int main() {
const auto personFullName = faker::Person::fullName();
const auto personFullName = faker::person::fullName();
std::cout << "Person full name: " << personFullName << std::endl;

const auto jobTitle = faker::Person::jobTitle();
const auto jobTitle = faker::person::jobTitle();
std::cout << "Person job title: " << jobTitle << std::endl;

const auto hobby = faker::Person::hobby();
const auto hobby = faker::person::hobby();
std::cout << "Person hobby: " << hobby << std::endl;

const auto language = faker::Person::language();
const auto language = faker::person::language();
std::cout << "Person language: " << language << std::endl;

const auto nationality = faker::Person::nationality();
const auto nationality = faker::person::nationality();
std::cout << "Person nationality: " << nationality << std::endl;

const auto chineseZodiac = faker::Person::chineseZodiac();
const auto chineseZodiac = faker::person::chineseZodiac();
std::cout << "Person chinese zodiac: " << chineseZodiac << std::endl;

const auto passport = faker::Person::passport();
const auto passport = faker::person::passport();
std::cout << "Person passport: " << passport << std::endl;

return EXIT_SUCCESS;
Expand Down
96 changes: 46 additions & 50 deletions include/faker-cxx/Person.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@

#include "types/Country.h"

namespace faker
namespace faker::person
{
enum class PassportCountry;
enum class Sex;
enum class SsnCountry;
enum class Language;

class Person
{
public:
/**
* @brief Returns a random first name.
*
Expand All @@ -24,12 +21,12 @@ class Person
* @returns First name starting with a capital letter.
*
* @code
* Person::firstName() // "Michael"
* Person::firstName(Country::England, Sex::Female) // "Emma"
* Person::firstName(Country::England, Sex::Male) // "Arthur"
* person::firstName() // "Michael"
* person::firstName(Country::England, Sex::Female) // "Emma"
* person::firstName(Country::England, Sex::Male) // "Arthur"
* @endcode
*/
static std::string_view firstName(std::optional<Country> country = std::nullopt,
std::string_view firstName(std::optional<Country> country = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
Expand All @@ -41,10 +38,10 @@ class Person
* @returns Last name starting with a capital letter.
*
* @code
* Person::lastName() // "Peterson"
* person::lastName() // "Peterson"
* @endcode
*/
static std::string_view lastName(std::optional<Country> country = std::nullopt,
std::string_view lastName(std::optional<Country> country = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
Expand All @@ -56,12 +53,12 @@ class Person
* @returns Full name starting with first name.
*
* @code
* Person::fullName() // "Marcia Robinson"
* Person::fullName(Country::England, Sex::Female) // "Jennifer Martin"
* Person::fullName(Country::England, Sex::Male) // "Samuel Walker"
* person::fullName() // "Marcia Robinson"
* person::fullName(Country::England, Sex::Female) // "Jennifer Martin"
* person::fullName(Country::England, Sex::Male) // "Samuel Walker"
* @endcode
*/
static std::string fullName(std::optional<Country> country = std::nullopt, std::optional<Sex> sex = std::nullopt);
std::string fullName(std::optional<Country> country = std::nullopt, std::optional<Sex> sex = std::nullopt);

/**
* @brief Returns a random name prefix.
Expand All @@ -71,12 +68,12 @@ class Person
* @returns Name prefix.
*
* @code
* Person::prefix() // "Miss"
* Person::prefix(Sex::Female) // "Ms."
* Person::prefix(Sex::Male) // "Mr."
* person::prefix() // "Miss"
* person::prefix(Sex::Female) // "Ms."
* person::prefix(Sex::Male) // "Mr."
* @endcode
*/
static std::string_view prefix(std::optional<Country> countryOpt = std::nullopt,
std::string_view prefix(std::optional<Country> countryOpt = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
Expand All @@ -85,10 +82,10 @@ class Person
* @returns Name suffix.
*
* @code
* Person::suffix() // "Jr."
* person::suffix() // "Jr."
* @endcode
*/
static std::string_view suffix(std::optional<Country> countryOpt = std::nullopt,
std::string_view suffix(std::optional<Country> countryOpt = std::nullopt,
std::optional<Sex> sex = std::nullopt);

/**
Expand All @@ -97,109 +94,109 @@ class Person
* @returns Bio.
*
* @code
* Person::bio() //"Developer"
* person::bio() //"Developer"
* @endcode
*/
static std::string bio();
std::string bio();

/**
* @brief Returns a sex.
*
* @returns Sex.
*
* @code
* Person::sex() // "Male"
* person::sex() // "Male"
* @endcode
*/
static std::string_view sex(std::optional<Language> language = std::nullopt);
std::string_view sex(std::optional<Language> language = std::nullopt);

/**
* @brief Returns a random gender.
*
* @returns Gender.
*
* @code
* Person::gender() // "Transexual woman"
* person::gender() // "Transexual woman"
* @endcode
*/
static std::string_view gender();
std::string_view gender();

/**
* @brief Returns a random job title.
*
* @returns Job title.
*
* @code
* Person::jobTitle() // "Global Accounts Engineer"
* person::jobTitle() // "Global Accounts Engineer"
* @endcode
*/
static std::string jobTitle();
std::string jobTitle();

/**
* @brief Returns a random job descriptor.
*
* @returns Job descriptor.
*
* @code
* Person::jobDescriptor() // "Senior"
* person::jobDescriptor() // "Senior"
* @endcode
*/
static std::string_view jobDescriptor();
std::string_view jobDescriptor();

/**
* @brief Returns a random job area.
*
* @returns Job area.
*
* @code
* Person::jobArea() // "Software"
* person::jobArea() // "Software"
* @endcode
*/
static std::string_view jobArea();
std::string_view jobArea();

/**
* @brief Returns a random job type.
*
* @returns Job type.
*
* @code
* Person::jobType() // "Engineer"
* person::jobType() // "Engineer"
* @endcode
*/
static std::string_view jobType();
std::string_view jobType();

/**
* @brief Returns a random hobby.
*
* @returns Hobby.
*
* @code
* Person::hobby() // "Gaming"
* person::hobby() // "Gaming"
* @endcode
*/
static std::string_view hobby();
std::string_view hobby();

/**
* @brief Returns a random language.
*
* @returns Language.
*
* @code
* Person::language() // "Polish"
* person::language() // "Polish"
* @endcode
*/
static std::string_view language();
std::string_view language();

/**
* @brief Returns a random nationality.
*
* @returns Nationality.
*
* @code
* Person::nationality() // "Romanian"
* person::nationality() // "Romanian"
* @endcode
*/
static std::string_view nationality();
std::string_view nationality();

/**
* @brief Returns a random SSN.
Expand All @@ -209,45 +206,44 @@ class Person
* @returns Social Security Number.
*
* @code
* Person::ssn() // "437-12-6854"
* Person::ssn(SsnCountry::Polish) // "95111901567"
* person::ssn() // "437-12-6854"
* person::ssn(SsnCountry::Polish) // "95111901567"
* @endcode
*/
static std::string ssn(std::optional<SsnCountry> country = std::nullopt);
std::string ssn(std::optional<SsnCountry> country = std::nullopt);

/**
* @brief Returns a random Western Zodiac
*
* @returns Western Zodiac
*
* @code
* Person::westernZodiac() // "Virgo"
* person::westernZodiac() // "Virgo"
* @endcode
*/
static std::string_view westernZodiac();
std::string_view westernZodiac();

/**
* @brief Returns a random Chinese Zodiac
*
* @returns Chinese Zodiac
*
* @code
* Person::chineseZodiac() // "Dragon"
* person::chineseZodiac() // "Dragon"
* @endcode
*/
static std::string_view chineseZodiac();
std::string_view chineseZodiac();

/**
* @brief Returns a random passport number from a given country
*
* @returns Passport
*
* @code
* Person::passport(PassportCountry::Romania) // "12345678"
* person::passport(PassportCountry::Romania) // "12345678"
* @endcode
*/
static std::string passport(std::optional<PassportCountry> country = std::nullopt);
};
std::string passport(std::optional<PassportCountry> country = std::nullopt);

enum class PassportCountry
{
Expand Down
8 changes: 4 additions & 4 deletions src/modules/company/Company.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ std::string name()
switch (number::integer<int>(3))
{
case 0:
companyName = FormatHelper::format("{} {}", Person::lastName(), Helper::arrayElement(companySuffixes));
companyName = FormatHelper::format("{} {}", person::lastName(), Helper::arrayElement(companySuffixes));
break;
case 1:
companyName = FormatHelper::format("{} {} {}", Person::firstName(), Person::lastName(), Person::jobArea());
companyName = FormatHelper::format("{} {} {}", person::firstName(), person::lastName(), person::jobArea());
break;
case 2:
companyName =
FormatHelper::format("{} {} {} Services", Person::firstName(), Person::lastName(), Person::jobArea());
FormatHelper::format("{} {} {} Services", person::firstName(), person::lastName(), person::jobArea());
break;
case 3:
companyName = FormatHelper::format("{} {} {} {}", Person::firstName(), Person::lastName(), Person::jobArea(),
companyName = FormatHelper::format("{} {} {} {}", person::firstName(), person::lastName(), person::jobArea(),
Helper::arrayElement(companySuffixes));
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/modules/git/Git.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ std::string commitEntry(std::optional<unsigned> dateYears, std::optional<unsigne
entry += commitSha();
}

const auto firstName = static_cast<std::string>(Person::firstName(country));
const auto lastName = static_cast<std::string>(Person::lastName(country));
const auto firstName = static_cast<std::string>(person::firstName(country));
const auto lastName = static_cast<std::string>(person::lastName(country));

entry += "\nAuthor: " + firstName + " " + lastName + " " + internet::email(firstName, lastName) + "\nDate: ";

Expand Down
4 changes: 2 additions & 2 deletions src/modules/internet/Internet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ std::vector<std::string_view> getAllEmojis()
std::string username(std::optional<std::string> firstNameInit, std::optional<std::string> lastNameInit,
Country country)
{
const auto firstName = firstNameInit ? *firstNameInit : Person::firstName(country);
const auto lastName = lastNameInit ? *lastNameInit : Person::lastName(country);
const auto firstName = firstNameInit ? *firstNameInit : person::firstName(country);
const auto lastName = lastNameInit ? *lastNameInit : person::lastName(country);

std::string username;

Expand Down
8 changes: 4 additions & 4 deletions src/modules/location/Location.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ std::string city(AddressCountry country)
const auto cityFormat = static_cast<std::string>(Helper::arrayElement(countryAddresses.cityFormats));

const auto dataGeneratorsMapping = std::unordered_map<std::string, std::function<std::string()>>{
{"firstName", [&country]() { return static_cast<std::string>(Person::firstName(getCountry(country))); }},
{"lastName", [&country]() { return static_cast<std::string>(Person::lastName(getCountry(country))); }},
{"firstName", [&country]() { return static_cast<std::string>(person::firstName(getCountry(country))); }},
{"lastName", [&country]() { return static_cast<std::string>(person::lastName(getCountry(country))); }},
{"cityName",
[&countryAddresses]() { return static_cast<std::string>(Helper::arrayElement(countryAddresses.cities)); }},
{"cityPrefix", [&countryAddresses]()
Expand Down Expand Up @@ -171,8 +171,8 @@ std::string street(AddressCountry country)
const auto streetFormat = static_cast<std::string>(Helper::arrayElement(countryAddresses.streetFormats));

const auto dataGeneratorsMapping = std::unordered_map<std::string, std::function<std::string()>>{
{"firstName", [&country]() { return static_cast<std::string>(Person::firstName(getCountry(country))); }},
{"lastName", [&country]() { return static_cast<std::string>(Person::lastName(getCountry(country))); }},
{"firstName", [&country]() { return static_cast<std::string>(person::firstName(getCountry(country))); }},
{"lastName", [&country]() { return static_cast<std::string>(person::lastName(getCountry(country))); }},
{"streetName", [&countryAddresses]()
{ return static_cast<std::string>(Helper::arrayElement(countryAddresses.streetNames)); }},
{"streetPrefix", [&countryAddresses]()
Expand Down
Loading

0 comments on commit d725fc7

Please sign in to comment.