summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSophie Forrest <git@sophieforrest.com>2024-09-06 01:34:01 +1200
committerSophie Forrest <git@sophieforrest.com>2024-09-06 01:34:01 +1200
commit151ab2e8a837242f9654be1280286dc9514fe49c (patch)
tree2396337d6ae42044200563727ee63282a7a07b29
parent7066484002cb8974ea3cb721db093a84335eaf97 (diff)
feat: basic parsing of prerequisites
-rw-r--r--src/main.rs37
1 files changed, 33 insertions, 4 deletions
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::<Vec<String>>();
+ } else {
+ let requirements = &requirements[4..].split(" (X) ").collect::<Vec<&str>>();
+
+ 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}");
+ }
}
}
}