forked from Anri/cal8tor
Capitalize + Type in models
This commit is contained in:
parent
75832958d8
commit
384dd9eaa9
3 changed files with 29 additions and 10 deletions
|
@ -6,6 +6,7 @@ use std::collections::HashMap;
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
self, get_semester, get_webpage, get_year,
|
self, get_semester, get_webpage, get_year,
|
||||||
models::{Position, TabChar},
|
models::{Position, TabChar},
|
||||||
|
Capitalize,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod models;
|
pub mod models;
|
||||||
|
@ -67,7 +68,8 @@ pub async fn timetable(
|
||||||
let day = matches
|
let day = matches
|
||||||
.name("day")
|
.name("day")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_str();
|
.as_str()
|
||||||
|
.capitalize();
|
||||||
|
|
||||||
let startime = matches
|
let startime = matches
|
||||||
.name("startime")
|
.name("startime")
|
||||||
|
@ -122,13 +124,6 @@ pub async fn timetable(
|
||||||
(schedules, (semester as usize, timetable))
|
(schedules, (semester as usize, timetable))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Data builded in the timetable webpage
|
|
||||||
type T = (
|
|
||||||
// Schedules
|
|
||||||
Vec<String>,
|
|
||||||
// Timetable per days with the semester as the key
|
|
||||||
(usize, Vec<models::Day>),
|
|
||||||
);
|
|
||||||
// Data builded in the info webpage
|
// Data builded in the info webpage
|
||||||
type D = HashMap<
|
type D = HashMap<
|
||||||
// Semester
|
// Semester
|
||||||
|
@ -138,7 +133,7 @@ type D = HashMap<
|
||||||
>;
|
>;
|
||||||
|
|
||||||
/// Build the timetable
|
/// Build the timetable
|
||||||
pub fn build(timetable: T, dates: D) -> Vec<models::Course> {
|
pub fn build(timetable: models::Timetable, dates: D) -> Vec<models::Course> {
|
||||||
let mut schedules = Vec::new();
|
let mut schedules = Vec::new();
|
||||||
// h1 => heure de début | m1 => minute de début
|
// h1 => heure de début | m1 => minute de début
|
||||||
// h2 => heure de fin | m2 => minute de fin
|
// h2 => heure de fin | m2 => minute de fin
|
||||||
|
|
|
@ -37,10 +37,18 @@ pub struct Course {
|
||||||
pub dtend: Option<chrono::DateTime<chrono::Utc>>,
|
pub dtend: Option<chrono::DateTime<chrono::Utc>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Day {
|
pub struct Day {
|
||||||
/// Day's name
|
/// Day's name
|
||||||
pub name: String,
|
pub name: String,
|
||||||
/// Ordered list of all the courses of the day
|
/// Ordered list of all the courses of the day
|
||||||
pub courses: Vec<Option<Course>>,
|
pub courses: Vec<Option<Course>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Data builded in the timetable webpage
|
||||||
|
pub type Timetable = (
|
||||||
|
// Schedules
|
||||||
|
Vec<String>,
|
||||||
|
// Timetable per days with the semester as the key
|
||||||
|
(usize, Vec<Day>),
|
||||||
|
);
|
||||||
|
|
16
src/utils.rs
16
src/utils.rs
|
@ -163,3 +163,19 @@ pub fn get_year(year: Option<i32>, semester: i8) -> String {
|
||||||
format!("{}-{}", wanted_year - 1, wanted_year)
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue