Skip to content
Permalink
Browse files

Make use of a default value

Signed-off-by: Thomas Lauf <thomas.lauf@tngtech.com>
  • Loading branch information...
lauft committed Apr 11, 2019
1 parent a672fd0 commit 6f439097d6fd55e19ee8f0964b6e4a30f6b9e200
Showing with 13 additions and 15 deletions.
  1. +5 −2 src/Rules.cpp
  2. +2 −1 src/Rules.h
  3. +6 −12 src/commands/CmdChart.cpp
@@ -141,13 +141,16 @@ bool Rules::has (const std::string& key) const

////////////////////////////////////////////////////////////////////////////////
// Return the configuration value given the specified key.
std::string Rules::get (const std::string& key) const
std::string Rules::get (const std::string &key, const std::string &defaultValue) const
{
auto found = _settings.find (key);

if (found != _settings.end ())
{
return found->second;
}

return "";
return defaultValue;
}

////////////////////////////////////////////////////////////////////////////////
@@ -41,7 +41,7 @@ class Rules
std::string file () const;

bool has (const std::string&) const;
std::string get (const std::string&) const;
std::string get (const std::string &key, const std::string &defaultValue = "") const;
int getInteger (const std::string&, int defaultValue = 0) const;
double getReal (const std::string&) const;
bool getBoolean (const std::string&) const;
@@ -78,6 +78,7 @@ class Rules
std::string _original_file {};
std::map <std::string, std::string> _settings {};
std::vector <std::string> _rule_types {"tags", "reports", "theme", "holidays", "exclusions"};

};

#endif
@@ -47,12 +47,10 @@ int CmdChartDay (
{
// Create a filter, and if empty, choose the current day.
auto filter = getFilter (cli);

if (! filter.is_started ())
{
if (rules.has ("reports.day.range"))
expandIntervalHint (rules.get ("reports.day.range"), filter);
else
filter.setRange (Datetime ("today"), Datetime ("tomorrow"));
expandIntervalHint (rules.get ("reports.day.range", ":day"), filter);
}

return renderChart (cli, "day", filter, rules, database);
@@ -66,12 +64,10 @@ int CmdChartWeek (
{
// Create a filter, and if empty, choose the current week.
auto filter = getFilter (cli);

if (! filter.is_started ())
{
if (rules.has ("reports.week.range"))
expandIntervalHint (rules.get ("reports.week.range"), filter);
else
filter.setRange (Datetime ("sow"), Datetime ("eow"));
expandIntervalHint (rules.get ("reports.week.range", ":week"), filter);
}

return renderChart (cli, "week", filter, rules, database);
@@ -85,12 +81,10 @@ int CmdChartMonth (
{
// Create a filter, and if empty, choose the current month.
auto filter = getFilter (cli);

if (! filter.is_started ())
{
if (rules.has ("reports.month.range"))
expandIntervalHint (rules.get ("reports.month.range"), filter);
else
filter.setRange (Datetime ("som"), Datetime ("eom"));
expandIntervalHint (rules.get ("reports.month.range", ":month"), filter);
}

return renderChart (cli, "month", filter, rules, database);

0 comments on commit 6f43909

Please sign in to comment.
You can’t perform that action at this time.