From fbccce7b7caa9f516b6222bca7ca63004b24dab4 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 29 Feb 2016 20:41:58 +0100 Subject: [PATCH 1/2] Add dep: libimagtag --- libimagentryfilter/Cargo.toml | 3 +++ libimagentryfilter/src/lib.rs | 1 + 2 files changed, 4 insertions(+) diff --git a/libimagentryfilter/Cargo.toml b/libimagentryfilter/Cargo.toml index 00aae942..6aa89527 100644 --- a/libimagentryfilter/Cargo.toml +++ b/libimagentryfilter/Cargo.toml @@ -13,3 +13,6 @@ toml = "0.1.27" [dependencies.libimagstore] path = "../libimagstore" +[dependencies.libimagtag] +path = "../libimagtag" + diff --git a/libimagentryfilter/src/lib.rs b/libimagentryfilter/src/lib.rs index 0a3c4316..80c966dd 100644 --- a/libimagentryfilter/src/lib.rs +++ b/libimagentryfilter/src/lib.rs @@ -5,6 +5,7 @@ extern crate regex; extern crate toml; extern crate libimagstore; +extern crate libimagtag; pub mod cli; pub mod builtin; From 6c50d88669b1ddcd2fb8918d9e3ef004fb7995fa Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Mon, 29 Feb 2016 20:42:11 +0100 Subject: [PATCH 2/2] Add tag filtering --- libimagentryfilter/src/lib.rs | 9 ++++ libimagentryfilter/src/tags/mod.rs | 77 ++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+) create mode 100644 libimagentryfilter/src/tags/mod.rs diff --git a/libimagentryfilter/src/lib.rs b/libimagentryfilter/src/lib.rs index 80c966dd..6234c1ac 100644 --- a/libimagentryfilter/src/lib.rs +++ b/libimagentryfilter/src/lib.rs @@ -7,7 +7,16 @@ extern crate toml; extern crate libimagstore; extern crate libimagtag; +// core functionality modules of the crate, +// these depend only on libimagstore + pub mod cli; pub mod builtin; pub mod filter; pub mod ops; + +// extended functionality of the crate +// these depend on other internal libraries than libimagstore and use the upper core modules for +// their functionality + +pub mod tags; diff --git a/libimagentryfilter/src/tags/mod.rs b/libimagentryfilter/src/tags/mod.rs new file mode 100644 index 00000000..6c7aaa3d --- /dev/null +++ b/libimagentryfilter/src/tags/mod.rs @@ -0,0 +1,77 @@ +use libimagstore::store::Entry; +use libimagtag::tagable::Tagable; +use libimagtag::tag::Tag; + +use filter::Filter; + +/// Check whether an Entry has a certain tag +pub struct HasTag { + tag: Tag, +} + +impl HasTag { + + pub fn new(tag: Tag) -> HasTag { + HasTag { + tag: tag, + } + } + +} + +impl Filter for HasTag { + + fn filter(&self, e: &Entry) -> bool { + e.has_tag(&self.tag).ok().unwrap_or(false) + } + +} + + +/// Check whether an Entry has all of these tags +pub struct HasAllTags { + tags: Vec, +} + +impl HasAllTags { + + pub fn new(tags: Vec) -> HasAllTags { + HasAllTags { + tags: tags, + } + } + +} + +impl Filter for HasAllTags { + + fn filter(&self, e: &Entry) -> bool { + e.has_tags(&self.tags).ok().unwrap_or(false) + } + +} + + +/// Check whether an Entry has any of these tags +pub struct HasAnyTags { + tags: Vec, +} + +impl HasAnyTags { + + pub fn new(tags: Vec) -> HasAnyTags { + HasAnyTags { + tags: tags, + } + } + +} + +impl Filter for HasAnyTags { + + fn filter(&self, e: &Entry) -> bool { + self.tags.iter().any(|tag| e.has_tag(tag).ok().unwrap_or(false)) + } + +} +