feat: implement comparison skeleton

This commit lays out the general idea of how the ComparisonData struct will work. It is expandable and I'm sure we will add more to it as time goes on.
This commit is contained in:
alphafetus committed 2025-11-18 13:17:32 -05:00
1 parent 431a8f244a
commit 83e46f4064
17 files changed
+1161 -89

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
use super::Comparison;
use crate::common::ValueType;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
pub enum TextComparison {
Matches,
NotMatches,
Contains,
NotContains,
}
impl Comparison for TextComparison {
fn evaluate(&self, comp_value: &ValueType, target_value: &ValueType) -> Result<bool, String> {
// All text comparisons require that the comp.member points to a Some(string) in the student_info,
// and that the target_value is also a Some(string).
let student_value = match comp_value {
ValueType::String(Some(value)) => value,
_ => return Err("Student value is not a string".into()),
};
let target_value = match target_value {
ValueType::String(Some(value)) => value,
_ => return Err("Target value is not a string".into()),
};
let matched = match self {
TextComparison::Matches => student_value == target_value,
TextComparison::NotMatches => student_value != target_value,
TextComparison::Contains => student_value.contains(target_value),
TextComparison::NotContains => !student_value.contains(target_value),
};
Ok(matched)
}
}