| 101 | } |
| 102 | |
| 103 | fn group_bang_eq_op( |
| 104 | &self, |
| 105 | other: &Box<dyn Value>, |
| 106 | group_op: &GroupComparisonOperator, |
| 107 | ) -> Result<Box<dyn Value>, String> { |
| 108 | if other.is_array_of(|element_type| element_type.is_text()) { |
| 109 | let elements = &other.as_array().unwrap(); |
| 110 | let mut matches_count = 0; |
| 111 | for element in elements.iter() { |
| 112 | if self.value != element.as_text().unwrap() { |
| 113 | matches_count += 1; |
| 114 | if GroupComparisonOperator::Any.eq(group_op) { |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | let result = match group_op { |
| 121 | GroupComparisonOperator::All => matches_count == elements.len(), |
| 122 | GroupComparisonOperator::Any => matches_count > 0, |
| 123 | }; |
| 124 | |
| 125 | return Ok(Box::new(BoolValue::new(result))); |
| 126 | } |
| 127 | Err("Unexpected type to perform `!=` with".to_string()) |
| 128 | } |
| 129 | |
| 130 | fn gt_op(&self, other: &Box<dyn Value>) -> Result<Box<dyn Value>, String> { |
| 131 | if let Some(other_text) = other.as_any().downcast_ref::<TextValue>() { |