From 68e08bed4f8f589d2e45bcd82a99090032a56b95 Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Sun, 26 May 2024 15:31:12 +0200 Subject: add prune logic --- aero-ical/src/lib.rs | 1 + aero-ical/src/prune.rs | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 aero-ical/src/prune.rs (limited to 'aero-ical') diff --git a/aero-ical/src/lib.rs b/aero-ical/src/lib.rs index f6b4ad4..696010a 100644 --- a/aero-ical/src/lib.rs +++ b/aero-ical/src/lib.rs @@ -5,3 +5,4 @@ /// integrates into Aerogramme pub mod parser; pub mod query; +pub mod prune; diff --git a/aero-ical/src/prune.rs b/aero-ical/src/prune.rs new file mode 100644 index 0000000..d04f700 --- /dev/null +++ b/aero-ical/src/prune.rs @@ -0,0 +1,40 @@ +use icalendar::parser::{Component, Property}; +use aero_dav::caltypes as cal; + +pub fn component<'a>(src: &'a Component<'a>, prune: &cal::Comp) -> Option> { + if src.name.as_str() != prune.name.as_str() { + return None + } + + let name = src.name.clone(); + + let properties = match &prune.prop_kind { + None => vec![], + Some(cal::PropKind::AllProp) => src.properties.clone(), + Some(cal::PropKind::Prop(l)) => src.properties.iter().filter_map(|prop| { + let sel_filt = match l.iter().find(|filt| filt.name.0.as_str() == prop.name.as_str()) { + Some(v) => v, + None => return None + }; + + match sel_filt.novalue { + None | Some(false) => Some(prop.clone()), + Some(true) => Some(Property { + name: prop.name.clone(), + params: prop.params.clone(), + val: "".into() + }), + } + }).collect::>(), + }; + + let components = match &prune.comp_kind { + None => vec![], + Some(cal::CompKind::AllComp) => src.components.clone(), + Some(cal::CompKind::Comp(many_inner_prune)) => src.components.iter().filter_map(|src_component| { + many_inner_prune.iter().find_map(|inner_prune| component(src_component, inner_prune)) + }).collect::>(), + }; + + Some(Component { name, properties, components }) +} -- cgit v1.2.3