Skip to content

Commit

Permalink
Merge f1785f1 into bec0d87
Browse files Browse the repository at this point in the history
  • Loading branch information
frosklis authored Mar 18, 2021
2 parents bec0d87 + f1785f1 commit 38a62e7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
16 changes: 13 additions & 3 deletions src/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,20 @@ impl<'a, T: Eq + Hash + HasName + Clone + FromDirective + HasAliases + Debug> Li
}
}

impl<T: Clone> List<T> {
impl<T: Clone + FromDirective + HasAliases + Debug + Eq + Hash + HasName> List<T> {
pub fn append(&mut self, other: &List<T>) {
self.list.extend(other.to_owned().list.into_iter());
self.aliases.extend(other.to_owned().aliases.into_iter());
for (key, value) in other.list.iter() {
if value.is_from_directive() {
self.list.insert(key.clone(), value.clone());
for alias in value.get_aliases().iter() {
self.aliases.insert(alias.to_lowercase(), key.clone());
}
} else {
if self.get(key).is_err() {
self.list.insert(key.clone(), value.clone());
}
}
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ impl ParsedLedger {
let mut payee_strs = HashSet::<String>::new();

// 1. Populate the directive lists

for transaction in self.transactions.iter() {
for p in transaction.postings.borrow().iter() {
account_strs.insert(p.account.clone());
Expand All @@ -84,6 +83,7 @@ impl ParsedLedger {
Err(_) => self.commodities.insert(Currency::from(alias.as_str())),
}
}

// Accounts
for alias in account_strs {
match self.accounts.get(&alias) {
Expand Down
1 change: 1 addition & 0 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use std::path::PathBuf;

use crate::models::{Account, Comment, Currency, Payee, Transaction};
use crate::{models, List};
use models::{HasAliases, HasName};
use pest::Parser;

mod include;
Expand Down
2 changes: 1 addition & 1 deletion src/parser/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,6 @@ pub(crate) fn parse_string(string: Pair<Rule>) -> String {
Rule::currency | Rule::commodity_in_directive => {
parse_string(string.into_inner().next().unwrap())
}
_ => string.as_str().to_string(),
_ => string.as_str().trim().to_string(),
}
}

0 comments on commit 38a62e7

Please sign in to comment.