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

feat: adding locale to medicine Module #1002

Merged
10 changes: 7 additions & 3 deletions include/faker-cxx/medicine.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,37 @@
#include <string_view>

#include "faker-cxx/export.h"
#include "faker-cxx/types/locale.h"

namespace faker::medicine
{
/**
* @brief Returns a random medical condition.
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Medical condition.
*
* @code
* faker::medicine::condition() // "AIDS"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view condition();
FAKER_CXX_EXPORT std::string_view condition(Locale locale = Locale::en_US);

/**
* @brief Returns a random medical test
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Medical test.
*
* @code
* faker::medicine::medicalTest() // "pulmonary auscultation"
* @endcode
*/
FAKER_CXX_EXPORT std::string_view medicalTest();
FAKER_CXX_EXPORT std::string_view medicalTest(Locale locale = Locale::en_US);

/**
* @brief Returns a random Medical specialty
* @param locale The locale. Defaults to `Locale::en_US`.
*
* @returns Medical specialty.
*
Expand All @@ -38,5 +42,5 @@ FAKER_CXX_EXPORT std::string_view medicalTest();
* @endcode
*/

FAKER_CXX_EXPORT std::string_view specialty();
FAKER_CXX_EXPORT std::string_view specialty(Locale locale = Locale::en_US);
}
28 changes: 22 additions & 6 deletions src/modules/medicine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,35 @@

namespace faker::medicine
{
std::string_view condition()

std::string_view condition(Locale locale)
{
return helper::randomElement(medicalConditions);
auto localeLocal = locale;
if (medicineMapSpan.find(locale) == medicineMapSpan.end())
{
localeLocal = Locale::en_US;
}
return helper::randomElement((medicineMapSpan.at(localeLocal)).medicalConditions);
}

std::string_view medicalTest()
std::string_view medicalTest(Locale locale)
{
return helper::randomElement(medicalTests);
auto localeLocal = locale;
if (medicineMapSpan.find(locale) == medicineMapSpan.end())
{
localeLocal = Locale::en_US;
}
return helper::randomElement((medicineMapSpan.at(localeLocal)).medicalTests);
}

std::string_view specialty()
std::string_view specialty(Locale locale)
{
return helper::randomElement(specialties);
auto localeLocal = locale;
if (medicineMapSpan.find(locale) == medicineMapSpan.end())
{
localeLocal = Locale::en_US;
}
return helper::randomElement((medicineMapSpan.at(localeLocal)).specialties);
}

}
Loading