[ledger] Core: haléře, dates, the event log and apply(), merchant keys and rules, one-to-one matching, import planning
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
//! The categories the app offers. A category is an id; the label is what the app shows.
|
||||
|
||||
pub const UNCATEGORISED: &str = "uncategorised";
|
||||
|
||||
/// `(id, label)` in the order the app lists them.
|
||||
pub const DEFAULT: &[(&str, &str)] = &[
|
||||
("groceries", "Groceries"),
|
||||
("eating-out", "Eating out"),
|
||||
("transport", "Transport"),
|
||||
("housing", "Housing"),
|
||||
("utilities", "Utilities"),
|
||||
("subscriptions", "Subscriptions"),
|
||||
("shopping", "Shopping"),
|
||||
("health", "Health"),
|
||||
("kids", "Kids"),
|
||||
("fun", "Fun"),
|
||||
("travel", "Travel"),
|
||||
("gifts", "Gifts"),
|
||||
("income", "Income"),
|
||||
("transfers", "Transfers"),
|
||||
("other", "Other"),
|
||||
(UNCATEGORISED, "Uncategorised"),
|
||||
];
|
||||
|
||||
/// A category id is lowercase ASCII letters, digits and `-`, 1–40 characters.
|
||||
pub fn is_valid(id: &str) -> bool {
|
||||
(1..=40).contains(&id.len()) && id.bytes().all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-')
|
||||
}
|
||||
|
||||
pub fn label(id: &str) -> &str {
|
||||
DEFAULT.iter().find(|(i, _)| *i == id).map(|(_, l)| *l).unwrap_or(id)
|
||||
}
|
||||
Reference in New Issue
Block a user