use crate::banking::account::Account; use crate::parsers::ini::IniFile; pub struct Asset { accounts : Vec } impl Asset { pub fn from_ini_file(file_name : &str) -> Asset { // read in ini file let t = crate::parsers::ini::IniFile::from_file(file_name); let file; match t { Ok(f) => file = f, Err(e) => panic!("asset: from_ini_file: could not read ini file: {}", e) } let mut accounts = Vec::new(); for (account_name, config) in file.sections { let mut tmp; match config.get("Institut") { Some(i) => tmp = i, None => panic!("asset: parse ini file: could not find \"Institute\" key for account {}", account_name) } let mut institute = String::from(""); if let Some(i) = tmp.get(0) { institute = i.to_string(); } let trans_files; match config.get("TransactionFile") { Some(i) => trans_files = i, None => panic!("asset: ini file: no \"TransactionFile\" for account: {}", account_name) } match config.get("IBAN") { Some(i) => tmp = i, None => panic!("asset: no name for account {}", account_name) } let mut iban = String::from(""); if let Some(i) = tmp.get(0) { iban = i.to_string(); } match config.get("GroupFile") { Some(i) => tmp = i, None => println!("no groupfile for account {}", account_name) } let mut groupFile = String::from(""); if let Some(i) = tmp.get(0) { groupFile = i.to_string(); } accounts.push(Account::new(account_name, iban, trans_files.to_vec(), institute, groupFile)); } Asset { accounts : accounts } } pub fn get_account_by_name(self, name : &str) -> Option { for account in self.accounts { if account.name == name { return Some(account); } } None } }