1pub struct Filters<'a> {
2 pub(crate) and: Option<u8>,
3 pub(crate) blank: Option<u8>,
4 pub(crate) filters: Vec<Filter<'a>>,
5}
6
7impl<'a> Filters<'a> {
8 pub fn new() -> Self {
9 Self {
10 and: None,
11 blank: None,
12 filters: vec![],
13 }
14 }
15 pub fn eq(vals: Vec<&'a str>) -> Self {
16 Self {
17 and: None,
18 blank: None,
19 filters: vals.iter().map(|&v| Filter::eq(v)).collect(),
20 }
21 }
22 pub fn blank() -> Self {
23 Self {
24 and: None,
25 blank: Some(1),
26 filters: vec![],
27 }
28 }
29 pub fn not_blank() -> Self {
30 Self {
31 and: None,
32 blank: None,
33 filters: vec![Filter::ne(" ")],
34 }
35 }
36 pub fn or(&mut self, filter: Filter<'a>) -> &mut Self {
37 self.filters.push(filter);
38 self
39 }
40 pub fn and(&mut self, filter: Filter<'a>) -> &mut Self {
41 self.and = Some(1);
42 self.filters.push(filter);
43 self
44 }
45
46 pub(crate) fn is_custom_filters(&self) -> bool {
47 self.filters.iter().any(|f| f.custom_filter)
48 }
49}
50
51pub struct Filter<'a> {
52 pub(crate) val: &'a str,
53 pub(crate) operator: Option<&'a str>,
54 custom_filter: bool,
55}
56
57impl<'a> Filter<'a> {
58 pub fn eq(val: &'a str) -> Self {
59 Self {
60 val,
61 operator: None,
62 custom_filter: false,
63 }
64 }
65 pub fn gt(val: &'a str) -> Self {
66 Self {
67 val,
68 operator: Some("greaterThan"),
69 custom_filter: true,
70 }
71 }
72 pub fn lt(val: &'a str) -> Self {
73 Self {
74 val,
75 operator: Some("lessThan"),
76 custom_filter: true,
77 }
78 }
79
80 pub fn ne(val: &'a str) -> Self {
81 Self {
82 val,
83 operator: Some("notEqual"),
84 custom_filter: true,
85 }
86 }
87}