diff options
Diffstat (limited to 'src/course.ml')
-rw-r--r-- | src/course.ml | 52 |
1 files changed, 32 insertions, 20 deletions
diff --git a/src/course.ml b/src/course.ml index 52aa062..4b9c914 100644 --- a/src/course.ml +++ b/src/course.ml @@ -1,5 +1,5 @@ (* - * Copyright (C) 2020 Alban Gruin + * Copyright (C) 2020, 2021 Alban Gruin * * ucs is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published @@ -48,18 +48,31 @@ let replace_entities str = type loc_and_sum = | Nothing - | Groups - | Location of string - | Summary of string * string - -let loc_and_sum_to_str category = function - | Nothing | Groups -> "", category - | Location location -> location, category - | Summary (location, summary) -> - let summary = match Astring.String.cut ~sep:" - " summary with - | None -> summary - | Some (_, str) -> str in - location, summary ^ " (" ^ category ^ ")" + | Groups of string list + | Location of string list * string + | Summary of string list * string * string + +let loc_and_sum_to_groups = function + | Nothing -> [] + | Groups groups | Location (groups, _) | Summary (groups, _, _) -> groups + +let loc_and_sum_to_location = function + | Nothing | Groups _ -> "" + | Location (_, location) | Summary (_, location, _) -> location + +let loc_and_sum_to_summary category = function + | Nothing | Groups _ | Location _ -> category + | Summary (_, _, summary) -> + let summary = match Astring.String.cut ~sep:" - " summary with + | None -> summary + | Some (_, str) -> str in + summary ^ " (" ^ category ^ ")" + +let loc_and_sum_to_event start stop category loc_and_sum = + let groups = loc_and_sum_to_groups loc_and_sum and + location = loc_and_sum_to_location loc_and_sum and + summary = loc_and_sum_to_summary category loc_and_sum in + Some (Ics.Event.make start stop summary location groups) let check_groups str = let group_affixes = ["L1 "; "L2 "; "L3 "; "L3P "; "M1 "; "M2 "; "DEUST "; @@ -68,20 +81,19 @@ let check_groups str = if List.fold_left (fun res affix -> res || Astring.String.is_prefix ~affix str) false group_affixes then - Groups + Groups (Astring.String.cuts ~empty:false ~sep:"<br />" @@ replace_entities str) else Nothing -let location_and_summary str category = +let location_and_summary str = let sep = "\r\n\r\n<br />\r\n\r\n" in let parts = Astring.String.cuts ~empty:false ~sep str in List.fold_right (fun str -> function | Nothing -> check_groups str - | Groups -> Location (replace_entities str) - | Location summary -> Summary (replace_entities str, summary) + | Groups groups -> Location (groups, replace_entities str) + | Location (groups, summary) -> Summary (groups, replace_entities str, summary) | Summary _ as res -> res) parts Nothing - |> loc_and_sum_to_str category let date = let date_format = "%FT%T" in @@ -92,10 +104,10 @@ let encoding = J.(conv (fun _ -> (None, None, "", ""), ()) (fun ((start, stop, description, category), ()) -> - let location, summary = location_and_summary description category in match start, stop with | Some start, Some stop -> - Some (Ics.Event.make start stop summary location) + let loc_and_sum = location_and_summary description in + loc_and_sum_to_event start stop category loc_and_sum | _, _ -> None) (merge_objs (obj4 |