Merge pull request #220 from matthiasbeyer/libimagentryfilter/tags

Libimagentryfilter/tags
This commit is contained in:
Matthias Beyer 2016-03-18 10:33:58 +01:00
commit fb35a5a2c7
3 changed files with 90 additions and 0 deletions

View file

@ -13,3 +13,6 @@ toml = "0.1.27"
[dependencies.libimagstore] [dependencies.libimagstore]
path = "../libimagstore" path = "../libimagstore"
[dependencies.libimagtag]
path = "../libimagtag"

View file

@ -5,8 +5,18 @@ extern crate regex;
extern crate toml; extern crate toml;
extern crate libimagstore; extern crate libimagstore;
extern crate libimagtag;
// core functionality modules of the crate,
// these depend only on libimagstore
pub mod cli; pub mod cli;
pub mod builtin; pub mod builtin;
pub mod filter; pub mod filter;
pub mod ops; 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;

View file

@ -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))
}
}