Add field_gt filter

This commit is contained in:
Matthias Beyer 2016-03-10 20:36:50 +01:00
parent 4de014c41a
commit 7b9f8dc8ad
2 changed files with 61 additions and 0 deletions

View file

@ -0,0 +1,60 @@
use libimagstore::store::Entry;
use builtin::header::field_path::FieldPath;
use builtin::header::field_predicate::FieldPredicate;
use builtin::header::field_predicate::Predicate;
use filter::Filter;
use toml::Value;
struct EqGt {
comp: Value
}
impl Predicate for EqGt {
fn evaluate(&self, v: Value) -> bool {
match &self.comp {
&Value::Integer(i) => {
match v {
Value::Integer(j) => i > j,
Value::Float(f) => (i as f64) > f,
_ => false,
}
},
&Value::Float(f) => {
match v {
Value::Integer(i) => f > (i as f64),
Value::Float(d) => f > d,
_ => false,
}
},
_ => false,
}
}
}
/// Check whether certain header field in a entry is equal to a value
pub struct FieldGt {
filter: FieldPredicate<EqGt>,
}
impl FieldGt {
pub fn new(path: FieldPath, expected_value: Value) -> FieldGt {
FieldGt {
filter: FieldPredicate::new(path, Box::new(EqGt { comp: expected_value })),
}
}
}
impl Filter for FieldGt {
fn filter(&self, e: &Entry) -> bool {
self.filter.filter(e)
}
}

View file

@ -1,6 +1,7 @@
pub mod field_eq; pub mod field_eq;
pub mod field_exists; pub mod field_exists;
pub mod field_grep; pub mod field_grep;
pub mod field_gt;
pub mod field_isempty; pub mod field_isempty;
pub mod field_istype; pub mod field_istype;
pub mod field_path; pub mod field_path;