aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHarald Eilertsen <haraldei@anduin.net>2018-12-18 14:08:17 +0100
committerHarald Eilertsen <haraldei@anduin.net>2018-12-18 14:52:24 +0100
commit183abd3316532531d5510e4ea7b87aeb1404a4a2 (patch)
treecb84db45e13c73317c43deea7e66f4d948e24f51 /src
parent9925eeefbe864b81b96dffdb67b69b2572eca679 (diff)
downloadicaltool-183abd3316532531d5510e4ea7b87aeb1404a4a2.tar.gz
icaltool-183abd3316532531d5510e4ea7b87aeb1404a4a2.tar.bz2
icaltool-183abd3316532531d5510e4ea7b87aeb1404a4a2.zip
Match events by simple pattern on given key.
Diffstat (limited to 'src')
-rw-r--r--src/main.rs22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 28575d5..0a52dc3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -62,8 +62,18 @@ fn read_icalendar_from_file(filename: &str) -> std::io::Result<Vec<ical::parser:
.collect())
}
-fn match_event(_event: &ical::parser::ical::component::IcalEvent, _pattern: &str) -> bool {
- true
+fn match_event(event: &ical::parser::ical::component::IcalEvent, pattern: &str) -> bool {
+ if pattern == "*" {
+ true
+ }
+ else {
+ let parts: Vec<&str> = pattern.split(':').collect();
+ let (key, pat) = (parts[0].to_uppercase(), parts[1]);
+
+ event.properties.iter()
+ .filter(|ref p| p.name == key && &p.value.clone().unwrap().matches(&pat).count() > &0)
+ .count() > 0
+ }
}
#[test]
@@ -74,6 +84,14 @@ fn match_all_events() {
assert_eq!(num_events, events.len());
}
+#[test]
+fn match_events_by_summary() {
+ let cal = read_icalendar_from_file("test/fixtures/events.ics").unwrap();
+ let num_events = cal[0].events.len();
+ let events:Vec<_> = cal[0].events.iter().filter(|ref event| match_event(&event, "summary:All")).collect();
+ assert_eq!(num_events - 1, events.len());
+}
+
fn main() {
let calendars = read_icalendar_from_file("test.ics").unwrap();
println!("Found {} calendard in file...", calendars.len());