summaryrefslogtreecommitdiff
path: root/src/banking/asset.rs
diff options
context:
space:
mode:
authorBenedict Börger <benedict@0xb8000.de>2019-04-14 19:12:21 +0200
committerBenedict Börger <benedict@0xb8000.de>2019-04-14 19:12:21 +0200
commitf28e8a59c781f24ed9399268cc2536aad0cf534d (patch)
tree5678dd6c12b5849ab15f9d63a49c9424d222390b /src/banking/asset.rs
parent7e8656cb6d086f364baeeb79a69a04555a6fd4f6 (diff)
[global] update all files
Diffstat (limited to 'src/banking/asset.rs')
-rw-r--r--src/banking/asset.rs57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/banking/asset.rs b/src/banking/asset.rs
new file mode 100644
index 0000000..7b7287b
--- /dev/null
+++ b/src/banking/asset.rs
@@ -0,0 +1,57 @@
+use crate::banking::account::Account;
+use crate::parsers::ini::IniFile;
+
+pub struct Asset {
+ accounts : Vec<Account>
+}
+
+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();
+ }
+ accounts.push(Account::new(account_name, iban, trans_files.to_vec(), institute));
+
+
+ }
+ Asset { accounts : accounts }
+ }
+
+ pub fn get_account_by_name(self, name : &str) -> Option<Account> {
+ for account in self.accounts {
+ if account.name == name {
+ return Some(account);
+ }
+ }
+ None
+ }
+}