From f0b458f6a1fdb89689aa415e75885cecc9bd4a56 Mon Sep 17 00:00:00 2001 From: Joshua Coles Date: Sun, 4 Feb 2024 14:03:13 +0000 Subject: [PATCH] Improve event summary parsing in course model This commit refines event summary parsing in the course model. Instead of splitting the summary, it uses regular expressions to extract the unit code and short lecture title more accurately. The update also includes better handling of events that don't match this format. --- app/models/course.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/models/course.rb b/app/models/course.rb index 1272ef5..d40b0c6 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -18,14 +18,15 @@ class Course < ApplicationRecord calendar = calendars.first events = calendar.events.map do |event| + # Example title include: PH40065B-Lab, PH40112-Lecc (Wk 19-25, 29-32), MA40049-Leca (LOIL), MA40049-Lecb summary = event.summary - match = summary.split('-') + match = /(^\w\w\d{5})-(\w+)/.match(summary) # Handle odd events we don't care about - next if match.length != 2 + next if match.nil? - unit_code = match[0] - short_lecture_title = match[1] + unit_code = match[1] + short_lecture_title = match[2] start_time = event.dtstart.to_time event_uuid = event.uid.to_s