Add builtin header check: Field is empty

This commit is contained in:
Matthias Beyer 2016-02-03 16:26:01 +01:00
parent 780410f29d
commit bcf8cf0447

View file

@ -0,0 +1,45 @@
use libimagstore::store::Entry;
use builtin::header::field_path::FieldPath;
use filter::Filter;
use toml::Value;
pub struct FieldIsEmpty {
header_field_path: FieldPath,
}
impl FieldIsEmpty {
pub fn new(path: FieldPath) -> FieldIsEmpty {
FieldIsEmpty {
header_field_path: path,
}
}
}
impl Filter for FieldIsEmpty {
fn filter(&self, e: &Entry) -> bool {
let header = e.get_header();
self.header_field_path
.walk(header)
.map(|v| {
match v {
Value::Array(a) => a.is_empty(),
Value::Boolean(_) => false,
Value::Float(_) => false,
Value::Integer(_) => false,
Value::String(_) => false,
Value::Table(t) => t.is_empty(),
_ => true,
}
})
.unwrap_or(false)
}
}