From 151ab2e8a837242f9654be1280286dc9514fe49c Mon Sep 17 00:00:00 2001 From: Sophie Forrest Date: Fri, 6 Sep 2024 01:34:01 +1200 Subject: feat: basic parsing of prerequisites --- src/main.rs | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index be3f808..ee7686e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -104,7 +104,7 @@ impl fmt::Display for Course<'_> { fn main() { tracing_subscriber::fmt() - .with_max_level(LevelFilter::ERROR) + .with_max_level(LevelFilter::INFO) .init(); let html = include_str!("../courses.html"); @@ -214,9 +214,38 @@ fn main() { working_course.points = points; - // if let Some(requirements) = details_split.last() { - // requirements.split(|c|) - // } + if let Some(requirements) = details_split.last().map(|s| s.trim()) { + if requirements.starts_with("(X)") { + working_course.restrictions = requirements[4..] + .split(&[';', ',']) + .map(str::trim) + .map(str::to_owned) + .collect::>(); + } else { + let requirements = &requirements[4..].split(" (X) ").collect::>(); + + working_course.prerequisites = requirements + .first() + .unwrap() + .split(&[',', ';']) + .map(str::trim) + .filter(|s| !s.is_empty()) + .map(str::to_owned) + .collect(); + + if requirements.len() > 1 { + working_course.restrictions = requirements + .last() + .unwrap() + .split(&[',', ';']) + .map(str::trim) + .map(str::to_owned) + .collect(); + } + } + + info!("{requirements}"); + } } } } -- cgit 1.4.1