From 8f8202282f0c7a5371a189eb61ae363730fe1e90 Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Thu, 23 May 2024 16:18:06 -0400 Subject: [PATCH] parent level DB has multiple tasks that each have a file and file modified timestamp associated --- pttodoer/src/main.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/pttodoer/src/main.rs b/pttodoer/src/main.rs index a52adc3..3d599c0 100644 --- a/pttodoer/src/main.rs +++ b/pttodoer/src/main.rs @@ -74,6 +74,22 @@ impl DB { } Ok(DB(result)) } + + pub fn incomplete(&self) -> Tasks { + let mut result = Tasks::new(); + for set in &self.0 { + result.0.extend(set.tasks.incomplete().0); + } + result + } + + pub fn due(&self) -> Tasks { + let mut result = Tasks::new(); + for set in &self.0 { + result.0.extend(set.tasks.due().0); + } + result + } } #[cfg(test)] @@ -82,18 +98,26 @@ mod test_taskss { #[test] fn read_dir_files() { - _ = DB::new("./src/testdata/taskss.d/files.d".to_string()).expect("failed to construct from dir of files"); + let db = DB::new("./src/testdata/taskss.d/files.d".to_string()).expect("failed to construct from dir of files"); + assert_eq!(2, db.0.len()); + assert_eq!(2, db.due().len()); + assert_eq!(2, db.incomplete().len()); } #[test] fn read_dir_file() { - _ = DB::new("./src/testdata/taskss.d/file.d".to_string()).expect("failed to construct from dir of a single file"); + let db = DB::new("./src/testdata/taskss.d/file.d".to_string()).expect("failed to construct from dir of a single file"); + assert_eq!(1, db.0.len()); + assert_eq!(1, db.due().len()); + assert_eq!(1, db.incomplete().len()); } #[test] fn read_single_file() { let db = DB::new("./src/testdata/taskss.d/single_file.yaml".to_string()).expect("failed to construct from single file"); assert_eq!(1, db.0.len()); + assert_eq!(1, db.due().len()); + assert_eq!(2, db.incomplete().len()); } } @@ -202,6 +226,14 @@ impl Tasks { self.0.len() } + pub fn incomplete(&self) -> Tasks { + Tasks(self.0.iter() + .filter(|x| !x.is_done()) + .map(|x| x.clone()) + .collect() + ) + } + pub fn due(&self) -> Tasks { Tasks(self.0.iter() .filter(|x| x.is_due())