Skip to content

Commit

Permalink
refactor book module data
Browse files Browse the repository at this point in the history
  • Loading branch information
cieslarmichal committed May 24, 2024
1 parent f8d09d6 commit c740665
Show file tree
Hide file tree
Showing 13 changed files with 583 additions and 670 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ set(FAKER_SOURCES
src/modules/animal/Animal.cpp
src/modules/animal/AnimalData.cpp
src/modules/book/Book.cpp
src/modules/book/BookData.cpp
src/modules/color/Color.cpp
src/modules/commerce/Commerce.cpp
src/modules/company/Company.cpp
Expand Down
42 changes: 10 additions & 32 deletions include/faker-cxx/Book.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <string>
#include <string_view>

namespace faker
{
Expand All @@ -16,7 +16,7 @@ class Book
* Book::title() // "Romeo and Juliet"
* @endcode
*/
static std::string title();
static std::string_view title();

/**
* @brief Returns a random book genre.
Expand All @@ -27,7 +27,7 @@ class Book
* Book::genre() // "Fantasy"
* @endcode
*/
static std::string genre();
static std::string_view genre();

/**
* @brief Returns a random book author.
Expand All @@ -38,7 +38,7 @@ class Book
* Book::author() // "Shakespeare, William"
* @endcode
*/
static std::string author();
static std::string_view author();

/**
* @brief Returns a random book publisher.
Expand All @@ -49,7 +49,7 @@ class Book
* Book::publisher() // "Addison-Wesley"
* @endcode
*/
static std::string publisher();
static std::string_view publisher();

/**
* @brief Returns a random book ISBN.
Expand All @@ -62,27 +62,16 @@ class Book
*/
static std::string isbn();

/**
* @brief Returns a random release year
*
* @returns int year
*
* @code
* Book::releaseYear() // 2016
* @endcode
*/
static int releaseYear();

/**
* @brief Returns the full name of a translator
*
* @returns std::string full name
* @returns std::string_view full name
*
* @code
* Book::translator() // "Eric Floyd"
* @endcode
*/
static std::string translator();
static std::string_view translator();

/**
* @brief Returns format of book
Expand All @@ -93,28 +82,17 @@ class Book
* Book::format() // BookFormat::paperback
* @endcode
*/
static std::string format();

/**
* @brief returns a random page number (50-999)
*
* @returns int page number
*
* @code
* Book::page() // 314
* @endcode
*/
static int page();
static std::string_view format();

/**
* @brief returns a random book series
*
* @returns std::string book series
* @returns std::string_view book series
*
* @code
* Book::series() // "Harry Potter"
* @endcode
*/
static std::string series();
static std::string_view series();
};
}
47 changes: 15 additions & 32 deletions src/modules/book/Book.cpp
Original file line number Diff line number Diff line change
@@ -1,38 +1,31 @@
#include "faker-cxx/Book.h"

#include "../../common/FormatHelper.h"
#include "data/Authors.h"
#include "data/BookFormat.h"
#include "data/Genres.h"
#include "data/Publishers.h"
#include "data/Series.h"
#include "data/Titles.h"
#include "data/Translators.h"
#include "faker-cxx/Date.h"
#include "BookData.h"
#include "faker-cxx/Helper.h"
#include "faker-cxx/Number.h"
#include "faker-cxx/String.h"

namespace faker
{
std::string Book::title()
std::string_view Book::title()
{
return Helper::arrayElement<std::string>(titles);
return Helper::arrayElement(titles);
}

std::string Book::genre()
std::string_view Book::genre()
{
return Helper::arrayElement<std::string>(genres);
return Helper::arrayElement(genres);
}

std::string Book::author()
std::string_view Book::author()
{
return Helper::arrayElement<std::string>(authors);
return Helper::arrayElement(authors);
}

std::string Book::publisher()
std::string_view Book::publisher()
{
return Helper::arrayElement<std::string>(publishers);
return Helper::arrayElement(publishers);
}

std::string Book::isbn()
Expand All @@ -41,28 +34,18 @@ std::string Book::isbn()
String::numeric(5), String::numeric(1));
}

int Book::releaseYear()
std::string_view Book::translator()
{
return Number::integer(1940, 2024);
return Helper::arrayElement(translators);
}

std::string Book::translator()
std::string_view Book::format()
{
return Helper::arrayElement<std::string>(translators);
return Helper::arrayElement(bookFormats);
}

std::string Book::format()
std::string_view Book::series()
{
return Helper::arrayElement<std::string>(bookFormats);
}

int Book::page()
{
return Number::integer(50, 999);
}

std::string Book::series()
{
return Helper::arrayElement<std::string>(bookSeries);
return Helper::arrayElement(bookSeries);
}
}
Loading

0 comments on commit c740665

Please sign in to comment.