summaryrefslogtreecommitdiffstats
path: root/cli/src/model.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-07-29 09:56:13 +0200
committerGustav Sörnäs <gustav@sornas.net>2021-07-29 10:19:31 +0200
commitccda716764ae84dee9f18f66e383b66c9e30b3b9 (patch)
tree40d5b679d76308233f599c57a4751b5ca14d1390 /cli/src/model.rs
parent5216a6a67d1bde60f4c872b8d8d966efe02dd4e4 (diff)
downloadmoney-ccda716764ae84dee9f18f66e383b66c9e30b3b9.tar.gz
list categories
Diffstat (limited to 'cli/src/model.rs')
-rw-r--r--cli/src/model.rs15
1 files changed, 12 insertions, 3 deletions
diff --git a/cli/src/model.rs b/cli/src/model.rs
index 01b645a..c70e43d 100644
--- a/cli/src/model.rs
+++ b/cli/src/model.rs
@@ -4,7 +4,6 @@ use std::convert::AsRef;
use std::fs;
use std::hash::{Hash, Hasher};
use std::path::{Path, PathBuf};
-use std::str::FromStr;
use structopt::StructOpt;
use twox_hash::XxHash64;
@@ -21,7 +20,7 @@ pub enum TransactionKind {
//TODO Transfer,
}
-impl FromStr for TransactionKind {
+impl std::str::FromStr for TransactionKind {
type Err = String;
fn from_str(s: &str) -> Result<Self, Self::Err> {
@@ -91,6 +90,17 @@ impl Store {
}
Ok(())
}
+
+ pub fn categories(&self) -> Vec<Category> {
+ let mut categories: Vec<_> = self
+ .transactions
+ .iter()
+ .map(|t| t.category.clone())
+ .collect();
+ categories.sort();
+ categories.dedup();
+ categories
+ }
}
impl Transaction {
@@ -109,4 +119,3 @@ impl Transaction {
h.finish()
}
}
-