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.
This commit is contained in:
parent
49282a72bf
commit
f0b458f6a1
@ -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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user