tilia-vobject 4.0.0.pre.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rubocop.yml +32 -0
  4. data/.simplecov +4 -0
  5. data/.travis.yml +3 -0
  6. data/CHANGELOG.sabre.md +626 -0
  7. data/CONTRIBUTING.md +25 -0
  8. data/Gemfile +17 -0
  9. data/Gemfile.lock +68 -0
  10. data/LICENSE +27 -0
  11. data/LICENSE.sabre +27 -0
  12. data/README.md +63 -0
  13. data/Rakefile +17 -0
  14. data/bin/vobject +7 -0
  15. data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
  16. data/lib/tilia/v_object/cli.rb +582 -0
  17. data/lib/tilia/v_object/component/available.rb +107 -0
  18. data/lib/tilia/v_object/component/v_alarm.rb +114 -0
  19. data/lib/tilia/v_object/component/v_availability.rb +128 -0
  20. data/lib/tilia/v_object/component/v_calendar.rb +468 -0
  21. data/lib/tilia/v_object/component/v_card.rb +457 -0
  22. data/lib/tilia/v_object/component/v_event.rb +127 -0
  23. data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
  24. data/lib/tilia/v_object/component/v_journal.rb +75 -0
  25. data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
  26. data/lib/tilia/v_object/component/v_todo.rb +147 -0
  27. data/lib/tilia/v_object/component.rb +591 -0
  28. data/lib/tilia/v_object/date_time_parser.rb +486 -0
  29. data/lib/tilia/v_object/document.rb +218 -0
  30. data/lib/tilia/v_object/element_list.rb +18 -0
  31. data/lib/tilia/v_object/eof_exception.rb +8 -0
  32. data/lib/tilia/v_object/free_busy_data.rb +149 -0
  33. data/lib/tilia/v_object/free_busy_generator.rb +465 -0
  34. data/lib/tilia/v_object/i_tip/broker.rb +909 -0
  35. data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
  36. data/lib/tilia/v_object/i_tip/message.rb +109 -0
  37. data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
  38. data/lib/tilia/v_object/i_tip.rb +10 -0
  39. data/lib/tilia/v_object/node.rb +192 -0
  40. data/lib/tilia/v_object/parameter.rb +327 -0
  41. data/lib/tilia/v_object/parse_exception.rb +7 -0
  42. data/lib/tilia/v_object/parser/json.rb +149 -0
  43. data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
  44. data/lib/tilia/v_object/parser/parser.rb +61 -0
  45. data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
  46. data/lib/tilia/v_object/parser/xml/element.rb +11 -0
  47. data/lib/tilia/v_object/parser/xml.rb +322 -0
  48. data/lib/tilia/v_object/parser.rb +10 -0
  49. data/lib/tilia/v_object/property/binary.rb +96 -0
  50. data/lib/tilia/v_object/property/boolean.rb +57 -0
  51. data/lib/tilia/v_object/property/flat_text.rb +52 -0
  52. data/lib/tilia/v_object/property/float_value.rb +107 -0
  53. data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
  54. data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
  55. data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
  56. data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
  57. data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
  58. data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
  59. data/lib/tilia/v_object/property/i_calendar.rb +14 -0
  60. data/lib/tilia/v_object/property/integer_value.rb +60 -0
  61. data/lib/tilia/v_object/property/text.rb +352 -0
  62. data/lib/tilia/v_object/property/time.rb +85 -0
  63. data/lib/tilia/v_object/property/unknown.rb +30 -0
  64. data/lib/tilia/v_object/property/uri.rb +78 -0
  65. data/lib/tilia/v_object/property/utc_offset.rb +56 -0
  66. data/lib/tilia/v_object/property/v_card/date.rb +31 -0
  67. data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
  68. data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
  69. data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
  70. data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
  71. data/lib/tilia/v_object/property/v_card.rb +13 -0
  72. data/lib/tilia/v_object/property.rb +532 -0
  73. data/lib/tilia/v_object/reader.rb +73 -0
  74. data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
  75. data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
  76. data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
  77. data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
  78. data/lib/tilia/v_object/recur.rb +10 -0
  79. data/lib/tilia/v_object/settings.rb +32 -0
  80. data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
  81. data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
  82. data/lib/tilia/v_object/splitter/v_card.rb +56 -0
  83. data/lib/tilia/v_object/splitter.rb +9 -0
  84. data/lib/tilia/v_object/string_util.rb +58 -0
  85. data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
  86. data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
  87. data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
  88. data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
  89. data/lib/tilia/v_object/time_zone_data.rb +10 -0
  90. data/lib/tilia/v_object/time_zone_util.rb +213 -0
  91. data/lib/tilia/v_object/uuid_util.rb +51 -0
  92. data/lib/tilia/v_object/v_card_converter.rb +354 -0
  93. data/lib/tilia/v_object/version.rb +9 -0
  94. data/lib/tilia/v_object/writer.rb +56 -0
  95. data/lib/tilia/v_object.rb +45 -0
  96. data/lib/tilia/vobject.rb +1 -0
  97. data/resources/schema/xcal.rng +1192 -0
  98. data/resources/schema/xcard.rng +388 -0
  99. data/test/test_helper.rb +56 -0
  100. data/test/v_object/attach_issue_test.rb +19 -0
  101. data/test/v_object/birthday_calendar_generator_test.rb +463 -0
  102. data/test/v_object/cli_mock.rb +19 -0
  103. data/test/v_object/cli_test.rb +460 -0
  104. data/test/v_object/component/available_test.rb +59 -0
  105. data/test/v_object/component/v_alarm_test.rb +160 -0
  106. data/test/v_object/component/v_availability_test.rb +388 -0
  107. data/test/v_object/component/v_calendar_test.rb +646 -0
  108. data/test/v_object/component/v_card_test.rb +258 -0
  109. data/test/v_object/component/v_event_test.rb +85 -0
  110. data/test/v_object/component/v_free_busy_test.rb +59 -0
  111. data/test/v_object/component/v_journal_test.rb +85 -0
  112. data/test/v_object/component/v_time_zone_test.rb +47 -0
  113. data/test/v_object/component/v_todo_test.rb +172 -0
  114. data/test/v_object/component_test.rb +419 -0
  115. data/test/v_object/date_time_parser_test.rb +526 -0
  116. data/test/v_object/document_test.rb +71 -0
  117. data/test/v_object/element_list_test.rb +27 -0
  118. data/test/v_object/em_client_test.rb +53 -0
  119. data/test/v_object/empty_parameter_test.rb +65 -0
  120. data/test/v_object/empty_value_issue_test.rb +25 -0
  121. data/test/v_object/fake_component.rb +21 -0
  122. data/test/v_object/free_busy_data_test.rb +285 -0
  123. data/test/v_object/free_busy_generator_test.rb +637 -0
  124. data/test/v_object/google_colon_escaping_test.rb +27 -0
  125. data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
  126. data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
  127. data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
  128. data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
  129. data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
  130. data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
  131. data/test/v_object/i_tip/broker_tester.rb +71 -0
  132. data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
  133. data/test/v_object/i_tip/evolution_test.rb +2644 -0
  134. data/test/v_object/i_tip/message_test.rb +25 -0
  135. data/test/v_object/issue153.vcf +352 -0
  136. data/test/v_object/issue153_test.rb +12 -0
  137. data/test/v_object/issue26_test.rb +25 -0
  138. data/test/v_object/issue36_work_around_test.rb +37 -0
  139. data/test/v_object/issue40_test.rb +26 -0
  140. data/test/v_object/issue64.vcf +351 -0
  141. data/test/v_object/issue64_test.rb +17 -0
  142. data/test/v_object/issue96_test.rb +22 -0
  143. data/test/v_object/issue_undefined_index_test.rb +24 -0
  144. data/test/v_object/j_cal_test.rb +150 -0
  145. data/test/v_object/j_card_test.rb +192 -0
  146. data/test/v_object/line_folding_issue_test.rb +19 -0
  147. data/test/v_object/mock_document.rb +6 -0
  148. data/test/v_object/parameter_test.rb +109 -0
  149. data/test/v_object/parser/json_test.rb +370 -0
  150. data/test/v_object/parser/mime_dir_test.rb +14 -0
  151. data/test/v_object/parser/quoted_printable_test.rb +78 -0
  152. data/test/v_object/parser/xml_test.rb +2563 -0
  153. data/test/v_object/property/binary_test.rb +12 -0
  154. data/test/v_object/property/boolean_test.rb +18 -0
  155. data/test/v_object/property/compound_test.rb +43 -0
  156. data/test/v_object/property/float_test.rb +20 -0
  157. data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
  158. data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
  159. data/test/v_object/property/i_calendar/duration_test.rb +14 -0
  160. data/test/v_object/property/i_calendar/recur_test.rb +39 -0
  161. data/test/v_object/property/text_test.rb +81 -0
  162. data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
  163. data/test/v_object/property/v_card/language_tag_test.rb +35 -0
  164. data/test/v_object/property_test.rb +338 -0
  165. data/test/v_object/reader_test.rb +403 -0
  166. data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
  167. data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
  168. data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
  169. data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
  170. data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
  171. data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
  172. data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
  173. data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
  174. data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
  175. data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
  176. data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
  177. data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
  178. data/test/v_object/recur/r_date_iterator_test.rb +44 -0
  179. data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
  180. data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
  181. data/test/v_object/slash_r_test.rb +15 -0
  182. data/test/v_object/splitter/i_calendar_test.rb +299 -0
  183. data/test/v_object/splitter/v_card_test.rb +173 -0
  184. data/test/v_object/string_util_test.rb +37 -0
  185. data/test/v_object/test_case.rb +42 -0
  186. data/test/v_object/time_zone_util_test.rb +271 -0
  187. data/test/v_object/uuid_util_test.rb +18 -0
  188. data/test/v_object/v_card21_test.rb +43 -0
  189. data/test/v_object/v_card_converter_test.rb +419 -0
  190. data/test/v_object/version_test.rb +15 -0
  191. data/test/v_object/writer_test.rb +33 -0
  192. data/tilia-vobject.gemspec +17 -0
  193. metadata +308 -0
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,25 @@
1
+ # Contributing
2
+
3
+ This project adheres to the [Open Code of Conduct][code-of-conduct]. By participating, you are expected to honor this code.
4
+ [code-of-conduct]: http://todogroup.org/opencodeofconduct/#tilia-vobject/tilia@jakobsack.de
5
+
6
+ This library is a port of [sabre/vobject](http://github.com/fruux/sabre-vobject). The ruby code should match the php code as good as possible. For more information refer to the [coding guidelines](https://tilia.github.io/coding_guidelines).
7
+
8
+ If you are having an issue [search the open issues](https://github.com/tilia/tilia-vobject/issues) or create an issue and we'll help point you in the right direction.
9
+
10
+ ## Submitting a Pull Request
11
+
12
+ * Fork the project on Github
13
+ * Install development dependencies (`bundle install`)
14
+ * Create a topic branch for your changes
15
+ * Ensure that you provide *documentation* and *test coverage* for your changes (patches won't be accepted without)
16
+ * Ensure that all tests pass (`bundle exec rake`)
17
+ * Create a [pull request](https://github.com/tilia/tilia-vobject/pulls) on Github (these are also a great place to start a conversation around a patch as early as possible)
18
+
19
+ ## Testing
20
+
21
+ To run the tests:
22
+
23
+ $ rake
24
+
25
+ If nothing complains, congratulations!
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Internal dependencies
4
+ gem 'tilia-xml', '~> 1.1'
5
+
6
+ # External dependencies
7
+ gem 'activesupport', '~> 4.2'
8
+ gem 'mail', '~> 2.6'
9
+ gem 'tzinfo', '~> 1.2'
10
+ gem 'rchardet', '~>1.6'
11
+
12
+ # Testing
13
+ gem 'rake'
14
+ gem 'minitest', '~> 5.8'
15
+ gem 'simplecov', '~> 0.10'
16
+ gem 'rubocop', '~> 0.34'
17
+ gem 'yard', '~> 0.8'
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ GEM
2
+ remote: https://rubygems.org/
3
+ specs:
4
+ activesupport (4.2.5)
5
+ i18n (~> 0.7)
6
+ json (~> 1.7, >= 1.7.7)
7
+ minitest (~> 5.1)
8
+ thread_safe (~> 0.3, >= 0.3.4)
9
+ tzinfo (~> 1.1)
10
+ ast (2.1.0)
11
+ astrolabe (1.3.1)
12
+ parser (~> 2.2)
13
+ docile (1.1.5)
14
+ i18n (0.7.0)
15
+ json (1.8.3)
16
+ libxml-ruby (2.8.0)
17
+ mail (2.6.3)
18
+ mime-types (>= 1.16, < 3)
19
+ mime-types (2.99)
20
+ minitest (5.8.3)
21
+ parser (2.2.3.0)
22
+ ast (>= 1.1, < 3.0)
23
+ powerpack (0.1.1)
24
+ rainbow (2.0.0)
25
+ rake (10.4.2)
26
+ rchardet (1.6.1)
27
+ rubocop (0.35.1)
28
+ astrolabe (~> 1.3)
29
+ parser (>= 2.2.3.0, < 3.0)
30
+ powerpack (~> 0.1)
31
+ rainbow (>= 1.99.1, < 3.0)
32
+ ruby-progressbar (~> 1.7)
33
+ tins (<= 1.6.0)
34
+ ruby-progressbar (1.7.5)
35
+ simplecov (0.10.0)
36
+ docile (~> 1.1.0)
37
+ json (~> 1.8)
38
+ simplecov-html (~> 0.10.0)
39
+ simplecov-html (0.10.0)
40
+ thread_safe (0.3.5)
41
+ tilia-uri (1.0.1)
42
+ activesupport (~> 4.2)
43
+ tilia-xml (1.2.0)
44
+ activesupport (~> 4.2)
45
+ libxml-ruby (~> 2.8)
46
+ tilia-uri (~> 1.0)
47
+ tins (1.6.0)
48
+ tzinfo (1.2.2)
49
+ thread_safe (~> 0.1)
50
+ yard (0.8.7.6)
51
+
52
+ PLATFORMS
53
+ ruby
54
+
55
+ DEPENDENCIES
56
+ activesupport (~> 4.2)
57
+ mail (~> 2.6)
58
+ minitest (~> 5.8)
59
+ rake
60
+ rchardet (~> 1.6)
61
+ rubocop (~> 0.34)
62
+ simplecov (~> 0.10)
63
+ tilia-xml (~> 1.1)
64
+ tzinfo (~> 1.2)
65
+ yard (~> 0.8)
66
+
67
+ BUNDLED WITH
68
+ 1.10.6
data/LICENSE ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (C) 2015 Jakob Sack (tilia@jakobsack.de)
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+ * Neither the name Tilia nor the names of its contributors
14
+ may be used to endorse or promote products derived from this software
15
+ without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
+ POSSIBILITY OF SUCH DAMAGE.
data/LICENSE.sabre ADDED
@@ -0,0 +1,27 @@
1
+ Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/)
2
+
3
+ All rights reserved.
4
+
5
+ Redistribution and use in source and binary forms, with or without modification,
6
+ are permitted provided that the following conditions are met:
7
+
8
+ * Redistributions of source code must retain the above copyright notice,
9
+ this list of conditions and the following disclaimer.
10
+ * Redistributions in binary form must reproduce the above copyright notice,
11
+ this list of conditions and the following disclaimer in the documentation
12
+ and/or other materials provided with the distribution.
13
+ * Neither the name Sabre nor the names of its contributors
14
+ may be used to endorse or promote products derived from this software
15
+ without specific prior written permission.
16
+
17
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
+ POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ tilia/vobject
2
+ =============
3
+
4
+ [![Build Status](https://travis-ci.org/tilia/tilia-vobject.svg?branch=master)](https://travis-ci.org/tilia/tilia-vobject)
5
+
6
+ **tilia/vobject is a port of [sabre/vobject](https://github.com/fruux/sabre-vobject)**
7
+
8
+ The sabre/vobject library allows you to easily parse and manipulate [iCalendar](https://tools.ietf.org/html/rfc5545)
9
+ and [vCard](https://tools.ietf.org/html/rfc6350) objects using PHP.
10
+
11
+ The goal of the VObject library is to create a very complete library, with an easy to use API.
12
+
13
+
14
+ Installation
15
+ ------------
16
+
17
+ Simply add tilia-vobject to your Gemfile and bundle it up:
18
+
19
+ ```ruby
20
+ gem 'tilia-vobject', '~> 4.0.0'
21
+ ```
22
+
23
+ Changes to sabre/vobject
24
+ ------------------------
25
+
26
+ ```php
27
+ Sabre\VObject\FreeBusyGenerator#setTimeRange(DateTimeInterface $start = null, DateTimeInterface $end = null)
28
+ ```
29
+
30
+ is replaced by
31
+
32
+ ```ruby
33
+ Tilia::VObject::FreeBusyGenerator#time_range=(Range<Time>)
34
+ ```
35
+
36
+ Unknown beginnings and ends can be replaced by `Tilia::VObject::Settings.min_date`
37
+ and `.max_date`.
38
+
39
+
40
+ ```php
41
+ Sabre\VObject\Property\ICalendar\DateTime#setDateTime(DateTimeInterface $dt, $isFloating = false)
42
+ Sabre\VObject\Property\ICalendar\DateTime#setDateTimes(array $dt, $isFloating = false)
43
+ ```
44
+
45
+ are replaced by
46
+
47
+ ```ruby
48
+ Tilia::VObject::Property::ICalendar#date_time=(Time)
49
+ Tilia::VObject::Property::ICalendar#date_times=(Array<Time>)
50
+ Tilia::VObject::Property::ICalendar#floating=(Boolean)
51
+ ```
52
+
53
+
54
+ Contributing
55
+ ------------
56
+
57
+ See [Contributing](CONTRIBUTING.md)
58
+
59
+
60
+ License
61
+ -------
62
+
63
+ tilia-vobject is licensed under the terms of the [three-clause BSD-license](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rubocop/rake_task'
4
+ require 'yard'
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.test_files = Dir.glob('test/**/*_test.rb')
8
+ t.libs << 'test'
9
+ end
10
+ RuboCop::RakeTask.new do |t|
11
+ t.options = ['--format', 'html', '--out', 'coverage/rubocop.html']
12
+ end
13
+ YARD::Rake::YardocTask.new do |t|
14
+ t.files = ['lib/**/*.rb', '-', 'README.md']
15
+ end
16
+
17
+ task(default: :test)
data/bin/vobject ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Expected to be called "bundle exec bin/vobject"
4
+ require './lib/tilia_vobject'
5
+
6
+ cli = Tilia::VObject::Cli.new
7
+ exit(cli.main(ARGV))
@@ -0,0 +1,142 @@
1
+ module Tilia
2
+ module VObject
3
+ # This class generates birthday calendars.
4
+ class BirthdayCalendarGenerator
5
+ # Input objects.
6
+ #
7
+ # @var array
8
+ # RUBY: attr_accessor :objects
9
+
10
+ # Default year.
11
+ # Used for dates without a year.
12
+ DEFAULT_YEAR = 2000
13
+
14
+ # Output format for the SUMMARY.
15
+ #
16
+ # @var string
17
+ # RUBY: attr_accessor :format
18
+
19
+ # Creates the generator.
20
+ #
21
+ # Check the setTimeRange and setObjects methods for details about the
22
+ # arguments.
23
+ #
24
+ # @param mixed objects
25
+ def initialize(objects = nil)
26
+ @objects = []
27
+ @format = '%1s\'s Birthday'
28
+
29
+ self.objects = objects if objects
30
+ end
31
+
32
+ # Sets the input objects.
33
+ #
34
+ # You must either supply a vCard as a string or as a Component/VCard object.
35
+ # It's also possible to supply an array of strings or objects.
36
+ #
37
+ # @param mixed objects
38
+ #
39
+ # @return void
40
+ def objects=(objects)
41
+ objects = [objects] unless objects.is_a?(Array)
42
+
43
+ @objects = []
44
+ objects.each do |object|
45
+ if object.is_a?(String)
46
+ v_obj = Reader.read(object)
47
+ unless v_obj.is_a?(Component::VCard)
48
+ fail ArgumentError, 'String could not be parsed as Component::VCard by setObjects'
49
+ end
50
+
51
+ @objects << v_obj
52
+ elsif object.is_a?(Component::VCard)
53
+ @objects << object
54
+ else
55
+ fail ArgumentError, 'You can only pass strings or Component::VCard arguments to setObjects'
56
+ end
57
+ end
58
+ end
59
+
60
+ # Sets the output format for the SUMMARY
61
+ #
62
+ # @param string format
63
+ #
64
+ # @return void
65
+ attr_writer :format
66
+
67
+ # Parses the input data and returns a VCALENDAR.
68
+ #
69
+ # @return Component/VCalendar
70
+ def result
71
+ calendar = Component::VCalendar.new
72
+
73
+ @objects.each do |object|
74
+ # Skip if there is no BDAY property.
75
+ next if object.select('BDAY').empty?
76
+
77
+ # We've seen clients (ez-vcard) putting "BDAY:" properties
78
+ # without a value into vCards. If we come across those, we'll
79
+ # skip them.
80
+ next if object['BDAY'].value.blank?
81
+
82
+ # We're always converting to vCard 4.0 so we can rely on the
83
+ # VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
84
+ object = object.convert(Document::VCARD40)
85
+
86
+ # Skip if the card has no FN property.
87
+ next unless object.key?('FN')
88
+
89
+ # Skip if the BDAY property is not of the right type.
90
+ next unless object['BDAY'].is_a?(Property::VCard::DateAndOrTime)
91
+
92
+ # Skip if we can't parse the BDAY value.
93
+ begin
94
+ date_parts = DateTimeParser.parse_v_card_date_time(object['BDAY'].value)
95
+ rescue ArgumentError
96
+ next
97
+ end
98
+
99
+ # Set a year if it's not set.
100
+ unknown_year = false
101
+
102
+ unless date_parts['year']
103
+ object['BDAY'] = "#{self.class::DEFAULT_YEAR}-#{date_parts['month']}-#{date_parts['date']}"
104
+ unknown_year = true
105
+ end
106
+
107
+ # Create event.
108
+ event = calendar.add(
109
+ 'VEVENT',
110
+ 'SUMMARY' => format(@format, object['FN'].value),
111
+ 'DTSTART' => Time.zone.parse(object['BDAY'].value),
112
+ 'RRULE' => 'FREQ=YEARLY',
113
+ 'TRANSP' => 'TRANSPARENT'
114
+ )
115
+
116
+ # add VALUE=date
117
+ event['DTSTART']['VALUE'] = 'DATE'
118
+
119
+ # Add X-SABRE-BDAY property.
120
+ if unknown_year
121
+ event.add(
122
+ 'X-SABRE-BDAY',
123
+ 'BDAY',
124
+ 'X-SABRE-VCARD-UID' => object['UID'].value,
125
+ 'X-SABRE-VCARD-FN' => object['FN'].value,
126
+ 'X-SABRE-OMIT-YEAR' => self.class::DEFAULT_YEAR
127
+ )
128
+ else
129
+ event.add(
130
+ 'X-SABRE-BDAY',
131
+ 'BDAY',
132
+ 'X-SABRE-VCARD-UID' => object['UID'].value,
133
+ 'X-SABRE-VCARD-FN' => object['FN'].value
134
+ )
135
+ end
136
+ end
137
+
138
+ calendar
139
+ end
140
+ end
141
+ end
142
+ end