Add field_lt filter
This commit is contained in:
parent
7b9f8dc8ad
commit
c76d654f9b
2 changed files with 61 additions and 0 deletions
60
libimagentryfilter/src/builtin/header/field_lt.rs
Normal file
60
libimagentryfilter/src/builtin/header/field_lt.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 EqLt {
|
||||||
|
comp: Value
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Predicate for EqLt {
|
||||||
|
|
||||||
|
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 FieldLt {
|
||||||
|
filter: FieldPredicate<EqLt>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FieldLt {
|
||||||
|
|
||||||
|
pub fn new(path: FieldPath, expected_value: Value) -> FieldLt {
|
||||||
|
FieldLt {
|
||||||
|
filter: FieldPredicate::new(path, Box::new(EqLt { comp: expected_value })),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Filter for FieldLt {
|
||||||
|
|
||||||
|
fn filter(&self, e: &Entry) -> bool {
|
||||||
|
self.filter.filter(e)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -4,5 +4,6 @@ pub mod field_grep;
|
||||||
pub mod field_gt;
|
pub mod field_gt;
|
||||||
pub mod field_isempty;
|
pub mod field_isempty;
|
||||||
pub mod field_istype;
|
pub mod field_istype;
|
||||||
|
pub mod field_lt;
|
||||||
pub mod field_path;
|
pub mod field_path;
|
||||||
pub mod field_predicate;
|
pub mod field_predicate;
|
||||||
|
|
Loading…
Reference in a new issue