use super::{AccountName, UnitName, Spanned}; mod parse; pub use parse::parse_ledger; mod print; pub use print::print_ledger; #[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq)] pub struct Balance { pub account: Spanned, pub amount: Spanned, pub unit: Spanned, } #[derive(Clone, Debug, PartialEq, PartialOrd, Eq, Ord)] pub struct LedgerEntry { pub datestamp: (u16, u8, u8), pub title: Option, pub balances: Vec>, } impl LedgerEntry { pub fn modifies(&self, account: AccountName) -> bool { self.balances.iter().any(|b| b.account.as_ref() == &account) } pub fn balance_for(&self, account: AccountName) -> Option<&Spanned> { self.balances.iter().find(|b| b.account.as_ref() == &account) } pub fn split_balances( &self, account: AccountName, ) -> Option<(&Spanned, impl Iterator>)> { let index = self.balances.iter().position(|b| b.account.as_ref() == &account)?; Some(( &self.balances[index], self.balances[0..index] .iter() .chain(self.balances[index + 1..].iter()), )) } }