From c1506294466e266bf25aee007635db716855f1a4 Mon Sep 17 00:00:00 2001 From: Malte Tammena Date: Fri, 22 Oct 2021 16:48:46 +0200 Subject: [PATCH] Add pupils price tag --- src/config/mod.rs | 1 + src/meal/mod.rs | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/config/mod.rs b/src/config/mod.rs index f55ede5..5dbdb51 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -156,6 +156,7 @@ arg_enum! { pub enum PriceTags { Student, Employee, + Pupil, Other, } } diff --git a/src/meal/mod.rs b/src/meal/mod.rs index caf9d26..f9f2745 100644 --- a/src/meal/mod.rs +++ b/src/meal/mod.rs @@ -46,9 +46,10 @@ pub struct Meta { #[derive(Debug, Clone, Serialize, Deserialize)] #[cfg_attr(debug, serde(deny_unknown_fields))] pub struct Prices { - students: f32, - employees: f32, - others: f32, + students: Option, + employees: Option, + pupils: Option, + others: Option, } #[derive(Debug, Clone, Hash, PartialEq, Eq)] @@ -165,6 +166,9 @@ impl Prices { if price_tags.contains(&PriceTags::Employee) { values.push(self.employees); } + if price_tags.contains(&PriceTags::Pupil) { + values.push(self.pupils); + } if price_tags.contains(&PriceTags::Other) { values.push(self.others); } @@ -172,7 +176,10 @@ impl Prices { }; let price_tags: Vec<_> = price_tags .into_iter() - .map(|tag| format!("{:.2}€", tag)) + .map(|tag| match tag { + Some(tag) => color!(format!("{:.2}€", tag); bright_green), + None => color!(String::from("-.--€"); bright_black), + }) .map(|tag| color!(tag; bright_green)) .collect(); match price_tags.len() {