summaryrefslogtreecommitdiffstats
path: root/libimagentryfilter
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-03-18 10:33:58 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-03-18 10:33:58 +0100
commitfb35a5a2c78580ce46713d6157db2f9a5cf30282 (patch)
tree3560235f5d00564a72285bc65d3105827ecf5198 /libimagentryfilter
parent2e068f11a924d3cddf213915b0d88a4834328079 (diff)
parent6c50d88669b1ddcd2fb8918d9e3ef004fb7995fa (diff)
Merge pull request #220 from matthiasbeyer/libimagentryfilter/tags
Libimagentryfilter/tags
Diffstat (limited to 'libimagentryfilter')
-rw-r--r--libimagentryfilter/Cargo.toml3
-rw-r--r--libimagentryfilter/src/lib.rs10
-rw-r--r--libimagentryfilter/src/tags/mod.rs77
3 files changed, 90 insertions, 0 deletions
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..6234c1ac 100644
--- a/libimagentryfilter/src/lib.rs
+++ b/libimagentryfilter/src/lib.rs
@@ -5,8 +5,18 @@ extern crate regex;
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))
+ }
+
+}
+