diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2016-02-29 20:42:11 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2016-03-11 15:13:34 +0100 |
commit | 6c50d88669b1ddcd2fb8918d9e3ef004fb7995fa (patch) | |
tree | 80a6e8afdf6bfc412b12be57f00448c14339622b /libimagentryfilter | |
parent | fbccce7b7caa9f516b6222bca7ca63004b24dab4 (diff) |
Add tag filtering
Diffstat (limited to 'libimagentryfilter')
-rw-r--r-- | libimagentryfilter/src/lib.rs | 9 | ||||
-rw-r--r-- | libimagentryfilter/src/tags/mod.rs | 77 |
2 files changed, 86 insertions, 0 deletions
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<Tag>, +} + +impl HasAllTags { + + pub fn new(tags: Vec<Tag>) -> 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<Tag>, +} + +impl HasAnyTags { + + pub fn new(tags: Vec<Tag>) -> 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)) + } + +} + |