Add field_gt filter
This commit is contained in:
parent
4de014c41a
commit
7b9f8dc8ad
2 changed files with 61 additions and 0 deletions
60
libimagentryfilter/src/builtin/header/field_gt.rs
Normal file
60
libimagentryfilter/src/builtin/header/field_gt.rs
Normal 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue