From 384dd9eaa988bcc45fe55f1373beb70caed4649b Mon Sep 17 00:00:00 2001 From: Mylloon Date: Thu, 28 Sep 2023 22:09:43 +0200 Subject: [PATCH] Capitalize + Type in models --- src/timetable.rs | 13 ++++--------- src/timetable/models.rs | 10 +++++++++- src/utils.rs | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/src/timetable.rs b/src/timetable.rs index 8adc0f9..bc02809 100644 --- a/src/timetable.rs +++ b/src/timetable.rs @@ -6,6 +6,7 @@ use std::collections::HashMap; use crate::utils::{ self, get_semester, get_webpage, get_year, models::{Position, TabChar}, + Capitalize, }; pub mod models; @@ -67,7 +68,8 @@ pub async fn timetable( let day = matches .name("day") .unwrap() - .as_str(); + .as_str() + .capitalize(); let startime = matches .name("startime") @@ -122,13 +124,6 @@ pub async fn timetable( (schedules, (semester as usize, timetable)) } -// Data builded in the timetable webpage -type T = ( - // Schedules - Vec, - // Timetable per days with the semester as the key - (usize, Vec), -); // Data builded in the info webpage type D = HashMap< // Semester @@ -138,7 +133,7 @@ type D = HashMap< >; /// Build the timetable -pub fn build(timetable: T, dates: D) -> Vec { +pub fn build(timetable: models::Timetable, dates: D) -> Vec { let mut schedules = Vec::new(); // h1 => heure de début | m1 => minute de début // h2 => heure de fin | m2 => minute de fin diff --git a/src/timetable/models.rs b/src/timetable/models.rs index bb813a3..0091185 100644 --- a/src/timetable/models.rs +++ b/src/timetable/models.rs @@ -37,10 +37,18 @@ pub struct Course { pub dtend: Option>, } -#[derive(Debug)] +#[derive(Clone, Debug)] pub struct Day { /// Day's name pub name: String, /// Ordered list of all the courses of the day pub courses: Vec>, } + +// Data builded in the timetable webpage +pub type Timetable = ( + // Schedules + Vec, + // Timetable per days with the semester as the key + (usize, Vec), +); diff --git a/src/utils.rs b/src/utils.rs index 5ecc3f1..b6a2ffa 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -163,3 +163,19 @@ pub fn get_year(year: Option, semester: i8) -> String { format!("{}-{}", wanted_year - 1, wanted_year) } } + +pub trait Capitalize { + /// Capitalize string + fn capitalize(&self) -> String; +} + +impl Capitalize for str { + fn capitalize(&self) -> String { + let mut string = self.to_owned(); + if let Some(r) = string.get_mut(0..1) { + r.make_ascii_uppercase(); + } + + string + } +}