From 661f1bd5575e139a51bad7f08061c677e00d8106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Mon, 2 Aug 2021 13:59:35 +0200 Subject: move code --- cli/src/search.rs | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'cli/src/search.rs') diff --git a/cli/src/search.rs b/cli/src/search.rs index ff9f772..7359b19 100644 --- a/cli/src/search.rs +++ b/cli/src/search.rs @@ -6,11 +6,6 @@ use crate::transaction::{Category, Transaction}; //TODO tests -pub struct Search<'t> { - filtered: Vec, - transactions: Vec<&'t Transaction>, -} - #[derive(Clone)] pub enum DateIsh { Absolute(NaiveDate), @@ -50,6 +45,22 @@ pub enum Comparison { LessOrEqual, } +fn parse_comparison(s: &str) -> Option<(Decimal, Comparison)> { + if s.starts_with(">=") { + Some((Decimal::from_str(&s[2..]).ok()?, Comparison::GreaterOrEqual)) + } else if s.starts_with("<=") { + Some((Decimal::from_str(&s[2..]).ok()?, Comparison::LessOrEqual)) + } else if s.starts_with("=") { + Some((Decimal::from_str(&s[1..]).ok()?, Comparison::Equal)) + } else if s.starts_with(">") { + Some((Decimal::from_str(&s[1..]).ok()?, Comparison::Greater)) + } else if s.starts_with("<") { + Some((Decimal::from_str(&s[1..]).ok()?, Comparison::Less)) + } else { + None + } +} + pub enum Constraint { Category(Category), Before(DateIsh), @@ -120,6 +131,11 @@ impl FilterType { } } +pub struct Search<'t> { + filtered: Vec, + transactions: Vec<&'t Transaction>, +} + impl<'t> Search<'t> { pub fn new(transactions: Vec<&'t Transaction>) -> Self { Self { @@ -167,19 +183,3 @@ impl<'t> Search<'t> { self } } - -fn parse_comparison(s: &str) -> Option<(Decimal, Comparison)> { - if s.starts_with(">=") { - Some((Decimal::from_str(&s[2..]).ok()?, Comparison::GreaterOrEqual)) - } else if s.starts_with("<=") { - Some((Decimal::from_str(&s[2..]).ok()?, Comparison::LessOrEqual)) - } else if s.starts_with("=") { - Some((Decimal::from_str(&s[1..]).ok()?, Comparison::Equal)) - } else if s.starts_with(">") { - Some((Decimal::from_str(&s[1..]).ok()?, Comparison::Greater)) - } else if s.starts_with("<") { - Some((Decimal::from_str(&s[1..]).ok()?, Comparison::Less)) - } else { - None - } -} -- cgit v1.2.1