parent level DB has multiple tasks that each have a file and file modified timestamp associated
parent
e81f221910
commit
8f8202282f
|
|
@ -74,6 +74,22 @@ impl DB {
|
||||||
}
|
}
|
||||||
Ok(DB(result))
|
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)]
|
#[cfg(test)]
|
||||||
|
|
@ -82,18 +98,26 @@ mod test_taskss {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn read_dir_files() {
|
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]
|
#[test]
|
||||||
fn read_dir_file() {
|
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]
|
#[test]
|
||||||
fn read_single_file() {
|
fn read_single_file() {
|
||||||
let db = DB::new("./src/testdata/taskss.d/single_file.yaml".to_string()).expect("failed to construct from 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.0.len());
|
||||||
|
assert_eq!(1, db.due().len());
|
||||||
|
assert_eq!(2, db.incomplete().len());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,6 +226,14 @@ impl Tasks {
|
||||||
self.0.len()
|
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 {
|
pub fn due(&self) -> Tasks {
|
||||||
Tasks(self.0.iter()
|
Tasks(self.0.iter()
|
||||||
.filter(|x| x.is_due())
|
.filter(|x| x.is_due())
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue