diff --git a/src/config/rule.rs b/src/config/rule.rs index a5cf6e4..c3cde7b 100644 --- a/src/config/rule.rs +++ b/src/config/rule.rs @@ -54,6 +54,10 @@ impl Rule { (all_adds_empty || any_add) && !any_sub } + pub fn is_non_empty_match(&self, meal: &MealComplete) -> bool { + !self.is_empty() && self.is_match(meal) + } + pub fn joined(self, other: Self) -> Self { Self { name: self.name.joined(other.name), @@ -61,9 +65,17 @@ impl Rule { category: self.category.joined(other.category), } } + + pub fn is_empty(&self) -> bool { + self.name.is_empty() && self.tag.is_empty() && self.category.is_empty() + } } impl TagRule { + pub fn is_empty(&self) -> bool { + self.add.is_empty() && self.sub.is_empty() + } + fn is_match_add(&self, meal: &MealComplete) -> bool { self.add.iter().any(|tag| meal.meta.tags.contains(tag)) } @@ -101,6 +113,10 @@ impl RegexRule { Self { add, sub } } + pub fn is_empty(&self) -> bool { + self.add.is_none() && self.sub.is_none() + } + fn is_match_add(&self, meal: &MealComplete) -> bool { match self.add { Some(ref rset) => rset.is_match(&meal.meta.category), diff --git a/src/meal/mod.rs b/src/meal/mod.rs index 149583d..c67145d 100644 --- a/src/meal/mod.rs +++ b/src/meal/mod.rs @@ -103,7 +103,7 @@ impl Meal { for meal in meals { let complete = meal.complete()?; if filter.is_match(&complete) { - let is_fav = favs.is_match(&complete); + let is_fav = favs.is_non_empty_match(&complete); println!("{}", *PRE); complete.print(is_fav); printed_at_least_one_meal = true;