rubyredrick-ri_cal 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. data/History.txt +3 -0
  2. data/Manifest.txt +122 -0
  3. data/README.txt +271 -0
  4. data/Rakefile +31 -0
  5. data/bin/ri_cal +8 -0
  6. data/component_attributes/alarm.yml +10 -0
  7. data/component_attributes/calendar.yml +4 -0
  8. data/component_attributes/component_property_defs.yml +180 -0
  9. data/component_attributes/event.yml +45 -0
  10. data/component_attributes/freebusy.yml +16 -0
  11. data/component_attributes/journal.yml +35 -0
  12. data/component_attributes/timezone.yml +3 -0
  13. data/component_attributes/timezone_period.yml +11 -0
  14. data/component_attributes/todo.yml +46 -0
  15. data/copyrights.txt +2 -0
  16. data/docs/draft-ietf-calsify-2446bis-08.txt +7280 -0
  17. data/docs/draft-ietf-calsify-rfc2445bis-09.txt +10416 -0
  18. data/docs/incrementers.txt +7 -0
  19. data/docs/rfc2445.pdf +0 -0
  20. data/lib/ri_cal/component/alarm.rb +22 -0
  21. data/lib/ri_cal/component/calendar.rb +199 -0
  22. data/lib/ri_cal/component/event.rb +30 -0
  23. data/lib/ri_cal/component/freebusy.rb +19 -0
  24. data/lib/ri_cal/component/journal.rb +22 -0
  25. data/lib/ri_cal/component/t_z_info_timezone.rb +124 -0
  26. data/lib/ri_cal/component/timezone/daylight_period.rb +26 -0
  27. data/lib/ri_cal/component/timezone/standard_period.rb +24 -0
  28. data/lib/ri_cal/component/timezone/timezone_period.rb +54 -0
  29. data/lib/ri_cal/component/timezone.rb +193 -0
  30. data/lib/ri_cal/component/todo.rb +26 -0
  31. data/lib/ri_cal/component.rb +224 -0
  32. data/lib/ri_cal/core_extensions/array/conversions.rb +15 -0
  33. data/lib/ri_cal/core_extensions/array.rb +7 -0
  34. data/lib/ri_cal/core_extensions/date/conversions.rb +27 -0
  35. data/lib/ri_cal/core_extensions/date.rb +13 -0
  36. data/lib/ri_cal/core_extensions/date_time/conversions.rb +27 -0
  37. data/lib/ri_cal/core_extensions/date_time.rb +13 -0
  38. data/lib/ri_cal/core_extensions/object/conversions.rb +20 -0
  39. data/lib/ri_cal/core_extensions/object.rb +8 -0
  40. data/lib/ri_cal/core_extensions/string/conversions.rb +32 -0
  41. data/lib/ri_cal/core_extensions/string.rb +8 -0
  42. data/lib/ri_cal/core_extensions/time/calculations.rb +153 -0
  43. data/lib/ri_cal/core_extensions/time/conversions.rb +27 -0
  44. data/lib/ri_cal/core_extensions/time/week_day_predicates.rb +88 -0
  45. data/lib/ri_cal/core_extensions/time.rb +11 -0
  46. data/lib/ri_cal/core_extensions.rb +6 -0
  47. data/lib/ri_cal/invalid_timezone_identifer.rb +20 -0
  48. data/lib/ri_cal/occurrence_enumerator.rb +172 -0
  49. data/lib/ri_cal/parser.rb +138 -0
  50. data/lib/ri_cal/properties/alarm.rb +390 -0
  51. data/lib/ri_cal/properties/calendar.rb +164 -0
  52. data/lib/ri_cal/properties/event.rb +1526 -0
  53. data/lib/ri_cal/properties/freebusy.rb +594 -0
  54. data/lib/ri_cal/properties/journal.rb +1240 -0
  55. data/lib/ri_cal/properties/timezone.rb +151 -0
  56. data/lib/ri_cal/properties/timezone_period.rb +416 -0
  57. data/lib/ri_cal/properties/todo.rb +1562 -0
  58. data/lib/ri_cal/property_value/array.rb +19 -0
  59. data/lib/ri_cal/property_value/cal_address.rb +12 -0
  60. data/lib/ri_cal/property_value/date.rb +119 -0
  61. data/lib/ri_cal/property_value/date_time/additive_methods.rb +43 -0
  62. data/lib/ri_cal/property_value/date_time/time_machine.rb +180 -0
  63. data/lib/ri_cal/property_value/date_time/timezone_support.rb +65 -0
  64. data/lib/ri_cal/property_value/date_time.rb +324 -0
  65. data/lib/ri_cal/property_value/duration.rb +106 -0
  66. data/lib/ri_cal/property_value/geo.rb +12 -0
  67. data/lib/ri_cal/property_value/integer.rb +13 -0
  68. data/lib/ri_cal/property_value/occurrence_list.rb +82 -0
  69. data/lib/ri_cal/property_value/period.rb +63 -0
  70. data/lib/ri_cal/property_value/recurrence_rule/enumeration_support_methods.rb +98 -0
  71. data/lib/ri_cal/property_value/recurrence_rule/enumerator.rb +77 -0
  72. data/lib/ri_cal/property_value/recurrence_rule/initialization_methods.rb +149 -0
  73. data/lib/ri_cal/property_value/recurrence_rule/negative_setpos_enumerator.rb +54 -0
  74. data/lib/ri_cal/property_value/recurrence_rule/numbered_span.rb +32 -0
  75. data/lib/ri_cal/property_value/recurrence_rule/occurence_incrementer.rb +794 -0
  76. data/lib/ri_cal/property_value/recurrence_rule/recurring_day.rb +132 -0
  77. data/lib/ri_cal/property_value/recurrence_rule/recurring_month_day.rb +61 -0
  78. data/lib/ri_cal/property_value/recurrence_rule/recurring_numbered_week.rb +34 -0
  79. data/lib/ri_cal/property_value/recurrence_rule/recurring_year_day.rb +50 -0
  80. data/lib/ri_cal/property_value/recurrence_rule/validations.rb +126 -0
  81. data/lib/ri_cal/property_value/recurrence_rule.rb +146 -0
  82. data/lib/ri_cal/property_value/text.rb +41 -0
  83. data/lib/ri_cal/property_value/uri.rb +12 -0
  84. data/lib/ri_cal/property_value/utc_offset.rb +34 -0
  85. data/lib/ri_cal/property_value.rb +110 -0
  86. data/lib/ri_cal/required_timezones.rb +56 -0
  87. data/lib/ri_cal/time_with_floating_timezone.rb +59 -0
  88. data/lib/ri_cal.rb +134 -0
  89. data/ri_cal.gemspec +47 -0
  90. data/sample_ical_files/from_ical_dot_app/test1.ics +38 -0
  91. data/script/console +10 -0
  92. data/script/destroy +14 -0
  93. data/script/generate +14 -0
  94. data/script/txt2html +71 -0
  95. data/spec/ri_cal/component/alarm_spec.rb +13 -0
  96. data/spec/ri_cal/component/calendar_spec.rb +55 -0
  97. data/spec/ri_cal/component/event_spec.rb +157 -0
  98. data/spec/ri_cal/component/freebusy_spec.rb +13 -0
  99. data/spec/ri_cal/component/journal_spec.rb +13 -0
  100. data/spec/ri_cal/component/t_z_info_timezone_spec.rb +37 -0
  101. data/spec/ri_cal/component/timezone_spec.rb +155 -0
  102. data/spec/ri_cal/component/todo_spec.rb +61 -0
  103. data/spec/ri_cal/component_spec.rb +212 -0
  104. data/spec/ri_cal/core_extensions/time/calculations_spec.rb +189 -0
  105. data/spec/ri_cal/core_extensions/time/week_day_predicates_spec.rb +46 -0
  106. data/spec/ri_cal/occurrence_enumerator_spec.rb +218 -0
  107. data/spec/ri_cal/parser_spec.rb +304 -0
  108. data/spec/ri_cal/property_value/date_spec.rb +22 -0
  109. data/spec/ri_cal/property_value/date_time_spec.rb +448 -0
  110. data/spec/ri_cal/property_value/duration_spec.rb +80 -0
  111. data/spec/ri_cal/property_value/period_spec.rb +50 -0
  112. data/spec/ri_cal/property_value/recurrence_rule/recurring_year_day_spec.rb +22 -0
  113. data/spec/ri_cal/property_value/recurrence_rule_spec.rb +1815 -0
  114. data/spec/ri_cal/property_value/text_spec.rb +14 -0
  115. data/spec/ri_cal/property_value/utc_offset_spec.rb +49 -0
  116. data/spec/ri_cal/property_value_spec.rb +111 -0
  117. data/spec/ri_cal/required_timezones_spec.rb +68 -0
  118. data/spec/ri_cal_spec.rb +54 -0
  119. data/spec/spec.opts +4 -0
  120. data/spec/spec_helper.rb +24 -0
  121. data/tasks/ri_cal.rake +403 -0
  122. data/tasks/spec.rake +35 -0
  123. metadata +201 -0
@@ -0,0 +1,14 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
+
6
+ describe RiCal::PropertyValue::Text do
7
+
8
+ it "should handle escapes according to RFC2445 Sec 4.3.11 p 45" do
9
+ expected = "this\\ has\, \nescaped\;\n\\x characters"
10
+ it = RiCal::PropertyValue::Text.new(nil, :value => 'this\\ has\, \nescaped\;\N\x characters')
11
+ it.ruby_value.should == expected
12
+ end
13
+
14
+ end
@@ -0,0 +1,49 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
5
+
6
+ describe RiCal::PropertyValue::UtcOffset do
7
+
8
+ describe "with a positive sign and seconds" do
9
+ before(:each) do
10
+ @it = RiCal::PropertyValue::UtcOffset.new(nil, :value => "+013015")
11
+ end
12
+
13
+ it "should have +1 as its sign" do
14
+ @it.sign.should == 1
15
+ end
16
+
17
+ it "should have 1 as its hours" do
18
+ @it.hours.should == 1
19
+ end
20
+
21
+ it "should have 30 as its minutes" do
22
+ @it.minutes.should == 30
23
+ end
24
+
25
+ it "should have 15 as its seconds" do
26
+ @it.seconds.should == 15
27
+ end
28
+ end
29
+
30
+ describe "with seconds omitted" do
31
+ before(:each) do
32
+ @it = RiCal::PropertyValue::UtcOffset.new(nil, :value => "+0130")
33
+ end
34
+
35
+ it "should have 0 as its seconds" do
36
+ @it.seconds.should == 0
37
+ end
38
+ end
39
+ describe "with a negative sign" do
40
+ before(:each) do
41
+ @it = RiCal::PropertyValue::UtcOffset.new(nil, :value => "-013015")
42
+ end
43
+
44
+ it "should have +1 as its sign" do
45
+ @it.sign.should == -1
46
+ end
47
+
48
+ end
49
+ end
@@ -0,0 +1,111 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[.. spec_helper])
5
+
6
+ describe RiCal::PropertyValue do
7
+
8
+ describe ".initialize" do
9
+
10
+ it "should reject a value starting with ';'" do
11
+ lambda {RiCal::PropertyValue.new(nil, :value => ";bogus")}.should raise_error {|err| err.message.should == "Invalid property value \";bogus\""}
12
+ end
13
+ end
14
+
15
+ describe "#date_or_date_time" do
16
+
17
+ it "should raise an exception on an invalid date" do
18
+ lambda {RiCal::PropertyValue.date_or_date_time(nil, :value => "foo")}.should raise_error
19
+ end
20
+
21
+
22
+ describe "rfc 2445 section 4.3.4 p 34" do
23
+ before(:each) do
24
+ @prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714")
25
+ end
26
+
27
+ it "should return a PropertyValue::Date" do
28
+ @prop.should be_kind_of(RiCal::PropertyValue::Date)
29
+ end
30
+
31
+ it "should set the correct date" do
32
+ @prop.to_ri_cal_ruby_value.should == Date.parse("Jul 14, 1997")
33
+ end
34
+ end
35
+
36
+ describe "rfc 2445 section 4.3.5 p 35" do
37
+ describe "FORM #1 date with local time p 36" do
38
+ before(:each) do
39
+ @prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456")
40
+ end
41
+
42
+ it "should return a PropertyValue::DateTime" do
43
+ @prop.should be_kind_of(RiCal::PropertyValue::DateTime)
44
+ end
45
+
46
+ it "should have the right ruby value" do
47
+ @prop.to_ri_cal_ruby_value.should == DateTime.parse("19970714T123456")
48
+ end
49
+
50
+ it "should have the right value" do
51
+ @prop.value.should == "19970714T123456"
52
+ end
53
+
54
+ it "should have a nil tzid" do
55
+ @prop.tzid.should be_nil
56
+ end
57
+ end
58
+
59
+ describe "FORM #2 date with UTC time p 36" do
60
+ before(:each) do
61
+ @prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456Z")
62
+ end
63
+
64
+ it "should return a PropertyValue::DateTime" do
65
+ @prop.should be_kind_of(RiCal::PropertyValue::DateTime)
66
+ end
67
+
68
+ it "should have the right value" do
69
+ @prop.value.should == "19970714T123456Z"
70
+ end
71
+
72
+ it "should have the right ruby value" do
73
+ @prop.to_ri_cal_ruby_value.should == DateTime.parse("19970714T123456Z")
74
+ end
75
+
76
+ it "should have a tzid of UTC" do
77
+ @prop.tzid.should == "UTC"
78
+ end
79
+
80
+ end
81
+
82
+ describe "FORM #3 date with local time and time zone reference p 36" do
83
+ before(:each) do
84
+ @prop = RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456", :params => {'TZID' => 'US-Eastern'})
85
+ end
86
+
87
+ it "should return a PropertyValue::DateTime" do
88
+ @prop.should be_kind_of(RiCal::PropertyValue::DateTime)
89
+ end
90
+
91
+ it "should have the right value" do
92
+ @prop.value.should == "19970714T123456"
93
+ end
94
+
95
+ it "should have the right ruby value" do
96
+ #TODO - what do we do about timezone with and without activesupport
97
+ @prop.to_ri_cal_ruby_value.should == DateTime.parse("19970714T123456")
98
+ end
99
+
100
+ it "should have the right tzid" do
101
+ @prop.tzid.should == "US-Eastern"
102
+ end
103
+
104
+ it "should raise an error if combined with a zulu time" do
105
+ lambda {RiCal::PropertyValue.date_or_date_time(nil, :value => "19970714T123456Z", :params => {:tzid => 'US-Eastern'})}.should raise_error
106
+ end
107
+ end
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,68 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[.. spec_helper])
5
+
6
+ require 'tzinfo'
7
+
8
+ describe RiCal::RequiredTimezones::RequiredTimezone do
9
+
10
+ before(:each) do
11
+ @tzid = "America/New_York"
12
+ @it = RiCal::RequiredTimezones::RequiredTimezone.new(@tzid)
13
+ end
14
+
15
+ it "should have the right timezone" do
16
+ @it.timezone.identifier.should == @tzid
17
+ end
18
+
19
+ it "should set the first_time to the first date_time added" do
20
+ dt1 = dt_prop(DateTime.parse("Mar 22, 2009 10:48"))
21
+ @it.add_datetime(dt1)
22
+ @it.first_time.should == dt1
23
+ end
24
+
25
+ it "should set the first_time to the earliest time added" do
26
+ dt1 = dt_prop(DateTime.parse("Mar 22, 2009 10:48"))
27
+ dt2 = dt_prop(DateTime.parse("Mar 22, 2009 9:00"))
28
+ dt3 = dt_prop(DateTime.parse("Mar 22, 2009 10:00"))
29
+ @it.add_datetime(dt1)
30
+ @it.add_datetime(dt2)
31
+ @it.add_datetime(dt3)
32
+ @it.first_time.should == dt2
33
+ end
34
+
35
+ it "should set the last_time to the first date_time added" do
36
+ dt1 = dt_prop(DateTime.parse("Mar 22, 2009 10:48"))
37
+ @it.add_datetime(dt1)
38
+ @it.last_time.should == dt1
39
+ end
40
+
41
+ it "should set the first_time to the earliest time added" do
42
+ dt1 = dt_prop(DateTime.parse("Mar 22, 2009 10:48"))
43
+ dt2 = dt_prop(DateTime.parse("Mar 22, 2009 9:00"))
44
+ dt3 = dt_prop(DateTime.parse("Mar 22, 2009 10:00"))
45
+ @it.add_datetime(dt1)
46
+ @it.add_datetime(dt2)
47
+ @it.add_datetime(dt3)
48
+ @it.last_time.should == dt1
49
+ end
50
+ end
51
+
52
+ describe RiCal::RequiredTimezones do
53
+ before(:each) do
54
+ @it = RiCal::RequiredTimezones.new
55
+ end
56
+
57
+ def localtime_and_zone(date_time, tzid = "US/Eastern")
58
+ [dt_prop(DateTime.parse(date_time), tzid), tzid]
59
+ end
60
+
61
+
62
+ it "should create a RequiredTimezone for each new timezone presented" do
63
+ @it.add_datetime(*localtime_and_zone("Mar 22, 2009 1:00"))
64
+ @it.add_datetime(*localtime_and_zone("Apr 16, 2008 12:00", "US/Central"))
65
+ @it.add_datetime(*localtime_and_zone("Apr 16, 2008 12:00"))
66
+ @it.required_zones.map {|zone| zone.tzid}.sort.should == ["US/Central", "US/Eastern"]
67
+ end
68
+ end
@@ -0,0 +1,54 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
5
+
6
+ describe RiCal do
7
+
8
+
9
+ describe "#parse" do
10
+
11
+ before(:each) do
12
+ @mock_parser = mock("parser", :parse => [])
13
+ RiCal::Parser.stub!(:new).and_return(@mock_parser)
14
+ end
15
+
16
+ it "should create a parser using the io parameter" do
17
+ io = StringIO.new("")
18
+ RiCal::Parser.should_receive(:new).with(io).and_return(@mock_parser)
19
+ RiCal.parse(io)
20
+ end
21
+
22
+ it "should delegate to the parser" do
23
+ io = StringIO.new("")
24
+ @mock_parser.should_receive(:parse)
25
+ RiCal.parse(io)
26
+ end
27
+
28
+ it "should return the results of the parse" do
29
+ io = StringIO.new("")
30
+ @mock_parser.stub!(:parse).and_return(:parse_result)
31
+ RiCal.parse(io).should == :parse_result
32
+ end
33
+ end
34
+
35
+ describe "#parse_string" do
36
+ before(:each) do
37
+ @mock_io = :mock_io
38
+ StringIO.stub!(:new).and_return(@mock_io)
39
+ RiCal.stub!(:parse)
40
+ end
41
+
42
+ it "should create a StringIO from the string" do
43
+ string = "test string"
44
+ StringIO.should_receive(:new).with(string)
45
+ RiCal.parse_string(string)
46
+ end
47
+
48
+ it "should parse" do
49
+ RiCal.should_receive(:parse).with(@mock_io)
50
+ RiCal.parse_string("")
51
+ end
52
+ end
53
+
54
+ end
data/spec/spec.opts ADDED
@@ -0,0 +1,4 @@
1
+ --colour
2
+ --format profile
3
+ --reverse
4
+ --backtrace
@@ -0,0 +1,24 @@
1
+ #- ©2009 Rick DeNatale
2
+ #- All rights reserved
3
+
4
+ require File.expand_path(File.join(File.dirname(__FILE__), %w[.. lib ri_cal]))
5
+ require 'cgi'
6
+
7
+ module Kernel
8
+ def rputs(*args)
9
+ puts *["<pre>", args.collect {|a| CGI.escapeHTML(a.to_s)}, "</pre>"] #if RiCal.debug
10
+ # puts *args
11
+ end
12
+ end
13
+
14
+ def date_time_with_zone(date_time, tzid = "US/Eastern")
15
+ result = date_time.dup
16
+ result.stub!(:acts_like_time?).and_return(true)
17
+ time_zone = mock("timezone", :identifier => tzid)
18
+ result.stub!(:time_zone).and_return(time_zone)
19
+ result
20
+ end
21
+
22
+ def dt_prop(date_time, tzid = "US/Eastern")
23
+ RiCal::PropertyValue::DateTime.convert(nil, date_time_with_zone(date_time, tzid))
24
+ end