-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove repetitive impl for excel parse
- Loading branch information
1 parent
813922a
commit e1ba2a0
Showing
10 changed files
with
223 additions
and
275 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "auto-frs-schedule" | ||
version = "2.1.4" | ||
version = "2.2.4" | ||
edition = "2021" | ||
description = "Automatically generate TC FRS schedule from Excel file" | ||
authors = ["Mohamad Kholid Bughowi <[email protected]>"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,74 @@ | ||
use std::path::PathBuf; | ||
use std::{collections::HashMap, path::PathBuf}; | ||
|
||
use anyhow::{Context, Result}; | ||
use calamine::{open_workbook, Reader, Xlsx}; | ||
|
||
use super::Excel; | ||
|
||
impl Excel { | ||
pub fn new(file_path: &PathBuf, sheet_name: &str) -> Result<Self> { | ||
pub fn new( | ||
file_path: &PathBuf, | ||
sheet_name: &str, | ||
list_subject: HashMap<String, String>, | ||
list_lecture: HashMap<String, String>, | ||
list_session: HashMap<String, i8>, | ||
) -> Result<Self> { | ||
let mut excel: Xlsx<_> = | ||
open_workbook(file_path).with_context(|| "Cannot open excel file")?; | ||
let range = excel | ||
.worksheet_range(sheet_name) | ||
.context("Error opening sheet, make sure sheet name is exists")? | ||
.with_context(|| format!("Could not read excel range from sheet {}", sheet_name))?; | ||
Ok(Self { range }) | ||
Ok(Self { | ||
range, | ||
list_lecture, | ||
list_session, | ||
list_subject, | ||
}) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::excel::{Excel, IntoMap}; | ||
use std::collections::HashMap; | ||
|
||
#[test] | ||
fn test_parse_subject() { | ||
let mut subject_map: HashMap<String, String> = HashMap::new(); | ||
subject_map.insert(String::from("jaringan komputer"), String::from("c636gggdd")); | ||
assert_eq!( | ||
Excel::subject_class_to_map("Jaringan Komputer A", &subject_map), | ||
Some(("c636gggdd".to_string(), "A".to_string())) | ||
); | ||
|
||
subject_map.insert(String::from("realitas x"), String::from("377hh7cch")); | ||
assert_eq!( | ||
Excel::subject_class_to_map("Realitas X", &subject_map), | ||
Some(("377hh7cch".to_string(), "-".to_string())) | ||
); | ||
subject_map.insert( | ||
String::from("interaksi manusia komputer"), | ||
String::from("wjjfhhfw888"), | ||
); | ||
assert_eq!( | ||
Excel::subject_class_to_map("Interaksi Manusia Komputer D - EN", &subject_map), | ||
Some(("wjjfhhfw888".to_string(), "D - EN".to_string())) | ||
); | ||
assert_eq!( | ||
Excel::subject_class_to_map("Interaksi Manusia Komputer - RKA", &subject_map), | ||
Some(("wjjfhhfw888".to_string(), "RKA".to_string())) | ||
); | ||
|
||
assert_eq!( | ||
Excel::subject_class_to_map("Jaringan Komputer - IUP", &subject_map), | ||
Some(("c636gggdd".to_string(), "IUP".to_string())) | ||
); | ||
|
||
subject_map.insert(String::from("dasar pemrograman"), String::from("cc773hhe")); | ||
assert_eq!( | ||
Excel::subject_class_to_map("Dasar Pemrograman F", &subject_map), | ||
Some(("cc773hhe".to_string(), "F".to_string())) | ||
); | ||
} | ||
} | ||
// #[cfg(test)] | ||
// mod test { | ||
// use crate::excel::{Excel, IntoMap}; | ||
// use std::collections::HashMap; | ||
|
||
// #[test] | ||
// fn test_parse_subject() { | ||
// let mut subject_map: HashMap<String, String> = HashMap::new(); | ||
// subject_map.insert(String::from("jaringan komputer"), String::from("c636gggdd")); | ||
// assert_eq!( | ||
// Excel::subject_class_to_map("Jaringan Komputer A", &subject_map), | ||
// Some(("c636gggdd".to_string(), "A".to_string())) | ||
// ); | ||
|
||
// subject_map.insert(String::from("realitas x"), String::from("377hh7cch")); | ||
// assert_eq!( | ||
// Excel::subject_class_to_map("Realitas X", &subject_map), | ||
// Some(("377hh7cch".to_string(), "-".to_string())) | ||
// ); | ||
// subject_map.insert( | ||
// String::from("interaksi manusia komputer"), | ||
// String::from("wjjfhhfw888"), | ||
// ); | ||
// assert_eq!( | ||
// Excel::subject_class_to_map("Interaksi Manusia Komputer D - EN", &subject_map), | ||
// Some(("wjjfhhfw888".to_string(), "D - EN".to_string())) | ||
// ); | ||
// assert_eq!( | ||
// Excel::subject_class_to_map("Interaksi Manusia Komputer - RKA", &subject_map), | ||
// Some(("wjjfhhfw888".to_string(), "RKA".to_string())) | ||
// ); | ||
|
||
// assert_eq!( | ||
// Excel::subject_class_to_map("Jaringan Komputer - IUP", &subject_map), | ||
// Some(("c636gggdd".to_string(), "IUP".to_string())) | ||
// ); | ||
|
||
// subject_map.insert(String::from("dasar pemrograman"), String::from("cc773hhe")); | ||
// assert_eq!( | ||
// Excel::subject_class_to_map("Dasar Pemrograman F", &subject_map), | ||
// Some(("cc773hhe".to_string(), "F".to_string())) | ||
// ); | ||
// } | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.