From 4c550e2cd60f8aa8925c6aeac8fc0a134b7379d2 Mon Sep 17 00:00:00 2001 From: Arthur Rosa Date: Sun, 30 Nov 2025 21:00:20 -0800 Subject: [PATCH] Add support for filtering blocking/non-blocking events Introduced a new `blocking` method in FilterableEventAdapter to determine if an event is blocking based on the TRANSP field. --- .ruby-version | 1 + README.md | 11 ++++++---- config.yml.example | 3 +++ .../filterable_event_adapter.rb | 5 +++++ spec/filterable_event_adapter_spec.rb | 20 +++++++++++++++++++ 5 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..6a81b4c --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +2.7.8 diff --git a/README.md b/README.md index d5fb0d9..58dd511 100644 --- a/README.md +++ b/README.md @@ -30,8 +30,11 @@ my_calendar_name: operator: matches # match against regex pattern val: # array of values also supported - '/Team A/i' + - field: blocking # blocking (TRANSP) field supported + operator: equals + val: true # true will filter out non-blocking events alarms: # (optional) create/clear alarms for filtered events - clear_existing: true # (optional) if true, existing alarms will be removed, default: false + clear_existing: true # (optional) if true, existing alarms will be removed, default: false triggers: # (optional) triggers for new alarms. Description will be the alarm summary, action is 'DISPLAY' - '-P1DT0H0M0S' # iso8601 supported - 2 days # supports full day[s], hour[s], minute[s], no combination in one trigger @@ -39,10 +42,10 @@ my_calendar_name: ### Variable substitution -It might be useful to inject configuration values as environment variable. -Variables are substituted if they begin with `ICAL_FILTER_PROXY_` and are defined in the configuration like `${ICAL_FILTER_PROXY_}`. +It might be useful to inject configuration values as environment variable. +Variables are substituted if they begin with `ICAL_FILTER_PROXY_` and are defined in the configuration like `${ICAL_FILTER_PROXY_}`. -Example: +Example: ```yaml api_key: ${ICAL_FILTER_PROXY_API_KEY} ``` diff --git a/config.yml.example b/config.yml.example index 5c3c413..bee591a 100644 --- a/config.yml.example +++ b/config.yml.example @@ -5,6 +5,9 @@ rota: - field: start_time operator: equals val: '09:00' + - field: blocking + operator: equals + val: true alarms: clear_existing: true triggers: diff --git a/lib/ical_filter_proxy/filterable_event_adapter.rb b/lib/ical_filter_proxy/filterable_event_adapter.rb index a4c9a09..74e0dfc 100644 --- a/lib/ical_filter_proxy/filterable_event_adapter.rb +++ b/lib/ical_filter_proxy/filterable_event_adapter.rb @@ -44,6 +44,11 @@ def end_components @end_components ||= DateComponents.new(dtend, options[:timezone]) end + # extract and rename TRANSP field to something more obvious + def blocking + raw_event.transp == 'OPAQUE' || raw_event.transp.nil? + end + def method_missing(method_sym, *args, &block) if method_sym.to_s =~ /(start|end)\_(\w+)/ components = self.send("#{$1}_components") diff --git a/spec/filterable_event_adapter_spec.rb b/spec/filterable_event_adapter_spec.rb index 6f782ea..39c7514 100644 --- a/spec/filterable_event_adapter_spec.rb +++ b/spec/filterable_event_adapter_spec.rb @@ -87,4 +87,24 @@ expect(adapter.end_date).to eq('2017-06-30') end end + + describe '#blocking' do + it 'returns true if transp is OPAQUE' do + test_event.transp = 'OPAQUE' + adapter = described_class.new(test_event) + expect(adapter.blocking).to be true + end + + it 'returns false if transp is TRANSPARENT' do + test_event.transp = 'TRANSPARENT' + adapter = described_class.new(test_event) + expect(adapter.blocking).to be false + end + + it 'returns true if transp is nil (default)' do + test_event.transp = nil + adapter = described_class.new(test_event) + expect(adapter.blocking).to be true + end + end end