Skip to content

Commit

Permalink
refactor: change system class to namespace (#724)
Browse files Browse the repository at this point in the history
* refactor: change system class to namespace

* fix: fix tests
  • Loading branch information
cieslarmichal authored Jun 24, 2024
1 parent eab8aa8 commit 5de4244
Show file tree
Hide file tree
Showing 6 changed files with 338 additions and 329 deletions.
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ All notable changes to this project will be documented in this file
* removed `weather.uvIndex` method, use `number.integer` instead
* removed `weather.humidity` method, use `number.integer` instead
* removed `weather.cloudCover` method, use `number.integer` instead
* changed classes to namespaces for functions grouping, for example use `number::integer` instead of `Number::integer`, applies to all modules
* changed classes to namespaces for functions grouping, for example use `number::integer` instead of `Number::integer`,
applies to all modules
* changed std::string to std::string_view in functions where is was possible
* changed function name from `sport` to `sportName` in sport module
* changed function name from `vehicle` to `vehicleName` in vehicle module
* changed function name from `timezone` to `timezoneRandom` in date module

* deleted function `commonFileType` from `System` module, use `system.fileType` instead

### Features

Expand Down
364 changes: 175 additions & 189 deletions include/faker-cxx/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

#include <optional>
#include <string>
#include <string_view>

namespace faker
namespace faker::system
{
struct FileOptions
{
Expand Down Expand Up @@ -37,192 +38,177 @@ struct NetworkInterfaceOptions
std::optional<std::string> interfaceSchema;
};

class System
{
public:
/**
* @brief Returns a random file name with extension.
*
* @param options An option struct.
*
* @returns Random file name with extension.
*
* @code
* System::fileName() // "injustice.mpeg"
*
* FileOptions options
* options.extensionCount = 3
* System::fileName(options) // "transformation.wav.mpeg.mp4"
*
* options.extensionRange.min = 1;
* options.extensionRange.max = 3;
* System::fileName(options) // "sparkle.png.pdf"
* @endcode
*/
static std::string fileName(const FileOptions& options = {});

/**
* @brief Returns a file extension.
*
* @param mimeType value of MimeType enum.
*
* @returns A file extension.
*
* @code
* System::fileExtension(MimeType::Image) // "png"
* @endcode
*/
static std::string fileExtension(const std::optional<FileType>& mimeType = std::nullopt);

/**
* Returns a random file name with a given extension or a commonly used extension.
*
* @param ext Optional extension parameter.
*
* @returns A random file name with a given extension or a commonly used extension.
*
* @code
* System::commonFileName() // "dollar.jpg"
* System::commonFileName("txt") // "global_borders_wyoming.txt"
* @endcode
*/
static std::string commonFileName(const std::optional<std::string>& ext = std::nullopt);

/**
* Returns a commonly used file extension.
*
* @returns A commonly used file extension.
*
* @code
* System::commonFileExtension() // "gif"
* @endcode
*/
static std::string commonFileExtension();

/**
* Returns a mime-type.
*
* @returns A mime-type.
*
* @code
* System::mimeType() // "video/vnd.vivo"
* @endcode
*/
static std::string mimeType();

/**
* Returns a commonly used file type.
*
* @returns A commonly used file type.
*
* @code
* System::commonFileType() // "audio"
* @endcode
*/
static std::string commonFileType();

/**
* Returns a commonly used file type.
*
* @returns A commonly used file type.
*
* @code
* System::fileType() // "image"
* @endcode
*/
static std::string fileType();

/**
* Returns a directory path.
*
* @returns A directory path.
*
* @code
* System::directoryPath() // "/etc/mail"
* @endcode
*/
static std::string directoryPath();

/**
* Returns a file path.
*
* @returns A file path.
*
* @code
* System::filePath() // "/usr/local/src/money.dotx"
* @endcode
*/
static std::string filePath();

/**
* Returns a semantic version.
*
* @returns A semantic version.
*
* @code
* System::semver() // "1.1.2"
* @endcode
*/
static std::string semver();

/**
* Returns a random network interface.
*
* @param options The options to use. Defaults to an empty options structure @see NetworkInterfaceOptions.h.
* @param options.interfaceType The interface type. Can be one of `en`, `wl`, `ww`.
* @param options.interfaceSchema The interface schema. Can be one of `index`, `slot`, `mac`, `pci`.
*
* @returns A random network interface.
*
* @code
* System::networkInterface() // "enp2s7f8"
*
* NetworkInterfaceOptions options;
* options.interfaceType = "wl";
* System::networkInterface(options) // "wlsf4d2"
*
* NetworkInterfaceOptions options;
* options.interfaceSchema = "mac";
* System::networkInterface(options) // "enxd17705ed394f"
*
* NetworkInterfaceOptions options;
* options.interfaceType = "en";
* options.interfaceSchema = "pci";
* System::networkInterface(options) // "enp1s9f1d2"
* @endcode
*/
static std::string networkInterface(const std::optional<NetworkInterfaceOptions>& options = {});

/**
* Returns a random cron expression.
*
* @param options The options to use. Defaults to an empty options structure @see CronOptions.h.
* @param options.includeYear Whether to include a year in the generated expression. Defaults to `false`.
* @param options.includeNonStandard Whether to include a @yearly, @monthly, @daily, etc text labels in the
* generated expression. Defaults to `false`.
*
* @returns A random cron expression.
*
* @code
* system.cron() // "22 * ? * ?"
*
* CronOptions options
* options.includeYear = true
* std::string cronExpr = System::cron(options) // "16 14 * 11 2 2038"
*
* CronOptions options
* options.includeYear = false
* std::string cronExpr = System::cron(options) // "16 14 * 11 2"
*
* CronOptions options
* options.includeNonStandard = false
* std::string cronExpr = System::cron(options) // 34 2 ? 8 *
*
* CronOptions options
* options.includeNonStandard = true
* std::string cronExpr = System::cron(options) // "@reboot"
* @endcode
*/
static std::string cron(const CronOptions& options = {});
};
/**
* @brief Returns a random file name with extension.
*
* @param options An option struct.
*
* @returns Random file name with extension.
*
* @code
* system::fileName() // "injustice.mpeg"
*
* FileOptions options
* options.extensionCount = 3
* system::fileName(options) // "transformation.wav.mpeg.mp4"
*
* options.extensionRange.min = 1;
* options.extensionRange.max = 3;
* system::fileName(options) // "sparkle.png.pdf"
* @endcode
*/
std::string fileName(const FileOptions& options = {});

/**
* @brief Returns a file extension.
*
* @param mimeType value of MimeType enum.
*
* @returns A file extension.
*
* @code
* system::fileExtension(MimeType::Image) // "png"
* @endcode
*/
std::string fileExtension(const std::optional<FileType>& mimeType = std::nullopt);

/**
* Returns a random file name with a given extension or a commonly used extension.
*
* @param ext Optional extension parameter.
*
* @returns A random file name with a given extension or a commonly used extension.
*
* @code
* system::commonFileName() // "dollar.jpg"
* system::commonFileName("txt") // "global_borders_wyoming.txt"
* @endcode
*/
std::string commonFileName(const std::optional<std::string>& ext = std::nullopt);

/**
* Returns a commonly used file extension.
*
* @returns A commonly used file extension.
*
* @code
* system::commonFileExtension() // "gif"
* @endcode
*/
std::string_view commonFileExtension();

/**
* Returns a mime-type.
*
* @returns A mime-type.
*
* @code
* system::mimeType() // "video/vnd.vivo"
* @endcode
*/
std::string_view mimeType();

/**
* Returns a commonly used file type.
*
* @returns A commonly used file type.
*
* @code
* system::fileType() // "audio"
* @endcode
*/
std::string_view fileType();

/**
* Returns a directory path.
*
* @returns A directory path.
*
* @code
* system::directoryPath() // "/etc/mail"
* @endcode
*/
std::string_view directoryPath();

/**
* Returns a file path.
*
* @returns A file path.
*
* @code
* system::filePath() // "/usr/local/src/money.dotx"
* @endcode
*/
std::string filePath();

/**
* Returns a semantic version.
*
* @returns A semantic version.
*
* @code
* system::semver() // "1.1.2"
* @endcode
*/
std::string semver();

/**
* Returns a random network interface.
*
* @param options The options to use. Defaults to an empty options structure @see NetworkInterfaceOptions.h.
* @param options.interfaceType The interface type. Can be one of `en`, `wl`, `ww`.
* @param options.interfaceSchema The interface schema. Can be one of `index`, `slot`, `mac`, `pci`.
*
* @returns A random network interface.
*
* @code
* system::networkInterface() // "enp2s7f8"
*
* NetworkInterfaceOptions options;
* options.interfaceType = "wl";
* system::networkInterface(options) // "wlsf4d2"
*
* NetworkInterfaceOptions options;
* options.interfaceSchema = "mac";
* system::networkInterface(options) // "enxd17705ed394f"
*
* NetworkInterfaceOptions options;
* options.interfaceType = "en";
* options.interfaceSchema = "pci";
* system::networkInterface(options) // "enp1s9f1d2"
* @endcode
*/
std::string networkInterface(const std::optional<NetworkInterfaceOptions>& options = {});

/**
* Returns a random cron expression.
*
* @param options The options to use. Defaults to an empty options structure @see CronOptions.h.
* @param options.includeYear Whether to include a year in the generated expression. Defaults to `false`.
* @param options.includeNonStandard Whether to include a @yearly, @monthly, @daily, etc text labels in the
* generated expression. Defaults to `false`.
*
* @returns A random cron expression.
*
* @code
* system.cron() // "22 * ? * ?"
*
* CronOptions options
* options.includeYear = true
* std::string cronExpr = system::cron(options) // "16 14 * 11 2 2038"
*
* CronOptions options
* options.includeYear = false
* std::string cronExpr = system::cron(options) // "16 14 * 11 2"
*
* CronOptions options
* options.includeNonStandard = false
* std::string cronExpr = system::cron(options) // 34 2 ? 8 *
*
* CronOptions options
* options.includeNonStandard = true
* std::string cronExpr = system::cron(options) // "@reboot"
* @endcode
*/
std::string cron(const CronOptions& options = {});
}
Loading

0 comments on commit 5de4244

Please sign in to comment.