Enter Book::getLanguages()

This commit is contained in:
Veloman Yunkan 2023-03-01 16:38:13 +04:00 committed by Matthieu Gautier
parent 12826a57bd
commit b1ad319d52
4 changed files with 26 additions and 2 deletions

View File

@ -80,6 +80,7 @@ class Book
const std::string& getTitle() const { return m_title; }
const std::string& getDescription() const { return m_description; }
const std::string& getLanguage() const { return m_language; }
const std::vector<std::string> getLanguages() const;
const std::string& getCreator() const { return m_creator; }
const std::string& getPublisher() const { return m_publisher; }
const std::string& getDate() const { return m_date; }

View File

@ -286,4 +286,9 @@ std::string Book::getCategoryFromTags() const
}
}
const std::vector<std::string> Book::getLanguages() const
{
return kiwix::split(m_language, ",");
}
}

View File

@ -388,8 +388,7 @@ Library::AttributeCounts Library::getBooksLanguagesWithCounts() const
for (const auto& pair: mp_impl->m_books) {
const auto& book = pair.second;
if (book.getOrigId().empty()) {
const std::string commaSeparatedLangList = book.getLanguage();
for ( const auto& lang : kiwix::split(commaSeparatedLangList, ",") ) {
for ( const auto& lang : book.getLanguages() ) {
++langsWithCounts[lang];
}
}

View File

@ -195,3 +195,22 @@ TEST(BookTest, getHumanReadableIdFromPath)
#endif
EXPECT_EQ("3plus2", path2HumanReadableId("3+2.zim"));
}
TEST(BookTest, getLanguages)
{
typedef std::vector<std::string> Langs;
{
const kiwix::Book book = makeBook(R"(id="abcd" language="fra")");
EXPECT_EQ(book.getLanguage(), "fra");
EXPECT_EQ(book.getLanguages(), Langs{ "fra" });
}
{
const kiwix::Book book = makeBook(R"(id="abcd" language="eng,ong,ing")");
EXPECT_EQ(book.getLanguage(), "eng,ong,ing");
EXPECT_EQ(book.getLanguages(), Langs({ "eng", "ong", "ing" }));
}
}