summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorhukl <contact@smyck.org>2009-03-16 20:58:49 +0100
committerhukl <contact@smyck.org>2009-03-18 12:16:59 +0100
commitd2bfbfd2810fbee673e43b2515db8bac527b3441 (patch)
tree1b46e8af44c871290a7a74ab17a8c7201e22f7a9 /lib
parentd957a33a0d50f00c1968c5d12e728bd73ea186b3 (diff)
Refactored Chaos Calendar by wrapping libical and introducing event and occurrence model. More improvements to come. Enables us to create events with reoccurrence and intervals etc.
Diffstat (limited to 'lib')
-rw-r--r--lib/chaos_calendar.rb35
-rwxr-xr-x[-rw-r--r--]lib/chaos_calendar/gen.sh0
2 files changed, 0 insertions, 35 deletions
diff --git a/lib/chaos_calendar.rb b/lib/chaos_calendar.rb
deleted file mode 100644
index b363ccb..0000000
--- a/lib/chaos_calendar.rb
+++ /dev/null
@@ -1,35 +0,0 @@
1require 'vpim'
2
3class Occurrence
4 def initialize start, event, node
5 @dtstart = start
6 @event = event
7 @node = node
8 end
9 attr_reader :dtstart, :event, :node
10end
11
12class ChaosCalendar
13 attr_reader :calendar
14 def initialize
15 @calendar = {}
16 end
17
18 def push cal, node
19 Vpim::Icalendar.decode( cal ).each { |c| c.events.each { |e| @calendar[e] = node } }
20 end
21
22 def occurrences start_time, end_time
23 occurr = []
24 @calendar.each { |e, node|
25 if e.occurs_in?( start_time, end_time )
26 e.occurences( end_time ) { |t|
27 occurr << Occurrence.new(t,e,node) if (t + (e.duration || 0)) >= start_time
28 }
29 end
30 }
31
32 return occurr.sort { |lhs, rhs| lhs.dtstart <=> rhs.dtstart }
33 end
34
35end
diff --git a/lib/chaos_calendar/gen.sh b/lib/chaos_calendar/gen.sh
index 2f5351a..2f5351a 100644..100755
--- a/lib/chaos_calendar/gen.sh
+++ b/lib/chaos_calendar/gen.sh