pub fn consensus_to_rating(consensus: &str) -> Option<f64> {
match consensus.trim().to_ascii_lowercase().as_str() {
"strong buy" => Some(1.0),
"buy" => Some(2.0),
"hold" => Some(3.0),
"sell" => Some(4.0),
"strong sell" => Some(5.0),
_ => None,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn consensus_strings() {
assert_eq!(consensus_to_rating("Strong Buy"), Some(1.0));
assert_eq!(consensus_to_rating(" hold "), Some(3.0));
assert_eq!(consensus_to_rating("Strong Sell"), Some(5.0));
assert_eq!(consensus_to_rating("n/a"), None);
}
}