49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
|
#ifndef LUNCH_REST_PARSER_H
|
||
|
#define LUNCH_REST_PARSER_H
|
||
|
|
||
|
#include "menu.hpp"
|
||
|
#include <sstream>
|
||
|
|
||
|
namespace LunchRest {
|
||
|
class Restaurant {
|
||
|
public:
|
||
|
Restaurant() = delete;
|
||
|
Restaurant(const std::string &url, const std::string &restaurant) :
|
||
|
_url(url), _restaurant(restaurant) {
|
||
|
menus.resize(5);
|
||
|
}
|
||
|
virtual ~Restaurant() = default;
|
||
|
const std::vector<Menu> &getMenus() {
|
||
|
return menus;
|
||
|
}
|
||
|
const std::string &getRestaurant() {
|
||
|
return _restaurant;
|
||
|
}
|
||
|
virtual void parse() = 0;
|
||
|
void clearMenus() {
|
||
|
menus.clear();
|
||
|
menus.resize(5);
|
||
|
for(auto &x : menus)
|
||
|
x.setInvalidMenu();
|
||
|
}
|
||
|
std::string jsonify(const std::vector<int> &days = {0,1,2,3,4}) {
|
||
|
std::stringstream ss{};
|
||
|
ss << "{\"restaurant\": \"" << getRestaurant() << "\", \"menus\": [";
|
||
|
for(auto &day : days) {
|
||
|
ss << menus[day].jsonify(permanent) << ",";
|
||
|
}
|
||
|
if(!days.empty())
|
||
|
ss.seekp(-1, ss.cur);
|
||
|
ss << "]}";
|
||
|
return ss.str();
|
||
|
}
|
||
|
protected:
|
||
|
std::string _url;
|
||
|
std::string _restaurant;
|
||
|
std::vector<Menu> menus;
|
||
|
std::vector<Meal> permanent;
|
||
|
};
|
||
|
} // end of namespace LunchRest
|
||
|
|
||
|
#endif
|