Skip to content

Commit 38a62e7

Browse files
authored
Merge f1785f1 into bec0d87
2 parents bec0d87 + f1785f1 commit 38a62e7

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

src/list.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,20 @@ impl<'a, T: Eq + Hash + HasName + Clone + FromDirective + HasAliases + Debug> Li
150150
}
151151
}
152152

153-
impl<T: Clone> List<T> {
153+
impl<T: Clone + FromDirective + HasAliases + Debug + Eq + Hash + HasName> List<T> {
154154
pub fn append(&mut self, other: &List<T>) {
155-
self.list.extend(other.to_owned().list.into_iter());
156-
self.aliases.extend(other.to_owned().aliases.into_iter());
155+
for (key, value) in other.list.iter() {
156+
if value.is_from_directive() {
157+
self.list.insert(key.clone(), value.clone());
158+
for alias in value.get_aliases().iter() {
159+
self.aliases.insert(alias.to_lowercase(), key.clone());
160+
}
161+
} else {
162+
if self.get(key).is_err() {
163+
self.list.insert(key.clone(), value.clone());
164+
}
165+
}
166+
}
157167
}
158168
}
159169

src/models/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ impl ParsedLedger {
6060
let mut payee_strs = HashSet::<String>::new();
6161

6262
// 1. Populate the directive lists
63-
6463
for transaction in self.transactions.iter() {
6564
for p in transaction.postings.borrow().iter() {
6665
account_strs.insert(p.account.clone());
@@ -84,6 +83,7 @@ impl ParsedLedger {
8483
Err(_) => self.commodities.insert(Currency::from(alias.as_str())),
8584
}
8685
}
86+
8787
// Accounts
8888
for alias in account_strs {
8989
match self.accounts.get(&alias) {

src/parser/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::path::PathBuf;
1212

1313
use crate::models::{Account, Comment, Currency, Payee, Transaction};
1414
use crate::{models, List};
15+
use models::{HasAliases, HasName};
1516
use pest::Parser;
1617

1718
mod include;

src/parser/utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ pub(crate) fn parse_string(string: Pair<Rule>) -> String {
6262
Rule::currency | Rule::commodity_in_directive => {
6363
parse_string(string.into_inner().next().unwrap())
6464
}
65-
_ => string.as_str().to_string(),
65+
_ => string.as_str().trim().to_string(),
6666
}
6767
}

0 commit comments

Comments
 (0)