tilia-vobject 4.0.0.pre.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +19 -0
- data/.rubocop.yml +32 -0
- data/.simplecov +4 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.sabre.md +626 -0
- data/CONTRIBUTING.md +25 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +68 -0
- data/LICENSE +27 -0
- data/LICENSE.sabre +27 -0
- data/README.md +63 -0
- data/Rakefile +17 -0
- data/bin/vobject +7 -0
- data/lib/tilia/v_object/birthday_calendar_generator.rb +142 -0
- data/lib/tilia/v_object/cli.rb +582 -0
- data/lib/tilia/v_object/component/available.rb +107 -0
- data/lib/tilia/v_object/component/v_alarm.rb +114 -0
- data/lib/tilia/v_object/component/v_availability.rb +128 -0
- data/lib/tilia/v_object/component/v_calendar.rb +468 -0
- data/lib/tilia/v_object/component/v_card.rb +457 -0
- data/lib/tilia/v_object/component/v_event.rb +127 -0
- data/lib/tilia/v_object/component/v_free_busy.rb +81 -0
- data/lib/tilia/v_object/component/v_journal.rb +75 -0
- data/lib/tilia/v_object/component/v_time_zone.rb +51 -0
- data/lib/tilia/v_object/component/v_todo.rb +147 -0
- data/lib/tilia/v_object/component.rb +591 -0
- data/lib/tilia/v_object/date_time_parser.rb +486 -0
- data/lib/tilia/v_object/document.rb +218 -0
- data/lib/tilia/v_object/element_list.rb +18 -0
- data/lib/tilia/v_object/eof_exception.rb +8 -0
- data/lib/tilia/v_object/free_busy_data.rb +149 -0
- data/lib/tilia/v_object/free_busy_generator.rb +465 -0
- data/lib/tilia/v_object/i_tip/broker.rb +909 -0
- data/lib/tilia/v_object/i_tip/i_tip_exception.rb +9 -0
- data/lib/tilia/v_object/i_tip/message.rb +109 -0
- data/lib/tilia/v_object/i_tip/same_organizer_for_all_components_exception.rb +13 -0
- data/lib/tilia/v_object/i_tip.rb +10 -0
- data/lib/tilia/v_object/node.rb +192 -0
- data/lib/tilia/v_object/parameter.rb +327 -0
- data/lib/tilia/v_object/parse_exception.rb +7 -0
- data/lib/tilia/v_object/parser/json.rb +149 -0
- data/lib/tilia/v_object/parser/mime_dir.rb +543 -0
- data/lib/tilia/v_object/parser/parser.rb +61 -0
- data/lib/tilia/v_object/parser/xml/element/key_value.rb +60 -0
- data/lib/tilia/v_object/parser/xml/element.rb +11 -0
- data/lib/tilia/v_object/parser/xml.rb +322 -0
- data/lib/tilia/v_object/parser.rb +10 -0
- data/lib/tilia/v_object/property/binary.rb +96 -0
- data/lib/tilia/v_object/property/boolean.rb +57 -0
- data/lib/tilia/v_object/property/flat_text.rb +52 -0
- data/lib/tilia/v_object/property/float_value.rb +107 -0
- data/lib/tilia/v_object/property/i_calendar/cal_address.rb +49 -0
- data/lib/tilia/v_object/property/i_calendar/date.rb +15 -0
- data/lib/tilia/v_object/property/i_calendar/date_time.rb +330 -0
- data/lib/tilia/v_object/property/i_calendar/duration.rb +65 -0
- data/lib/tilia/v_object/property/i_calendar/period.rb +124 -0
- data/lib/tilia/v_object/property/i_calendar/recur.rb +173 -0
- data/lib/tilia/v_object/property/i_calendar.rb +14 -0
- data/lib/tilia/v_object/property/integer_value.rb +60 -0
- data/lib/tilia/v_object/property/text.rb +352 -0
- data/lib/tilia/v_object/property/time.rb +85 -0
- data/lib/tilia/v_object/property/unknown.rb +30 -0
- data/lib/tilia/v_object/property/uri.rb +78 -0
- data/lib/tilia/v_object/property/utc_offset.rb +56 -0
- data/lib/tilia/v_object/property/v_card/date.rb +31 -0
- data/lib/tilia/v_object/property/v_card/date_and_or_time.rb +343 -0
- data/lib/tilia/v_object/property/v_card/date_time.rb +22 -0
- data/lib/tilia/v_object/property/v_card/language_tag.rb +41 -0
- data/lib/tilia/v_object/property/v_card/time_stamp.rb +74 -0
- data/lib/tilia/v_object/property/v_card.rb +13 -0
- data/lib/tilia/v_object/property.rb +532 -0
- data/lib/tilia/v_object/reader.rb +73 -0
- data/lib/tilia/v_object/recur/event_iterator.rb +417 -0
- data/lib/tilia/v_object/recur/no_instances_exception.rb +11 -0
- data/lib/tilia/v_object/recur/r_date_iterator.rb +138 -0
- data/lib/tilia/v_object/recur/r_rule_iterator.rb +717 -0
- data/lib/tilia/v_object/recur.rb +10 -0
- data/lib/tilia/v_object/settings.rb +32 -0
- data/lib/tilia/v_object/splitter/i_calendar.rb +95 -0
- data/lib/tilia/v_object/splitter/splitter_interface.rb +31 -0
- data/lib/tilia/v_object/splitter/v_card.rb +56 -0
- data/lib/tilia/v_object/splitter.rb +9 -0
- data/lib/tilia/v_object/string_util.rb +58 -0
- data/lib/tilia/v_object/time_zone_data/exchange_zones.rb +96 -0
- data/lib/tilia/v_object/time_zone_data/lotus_zones.rb +104 -0
- data/lib/tilia/v_object/time_zone_data/php_zones.rb +49 -0
- data/lib/tilia/v_object/time_zone_data/windows_zones.rb +121 -0
- data/lib/tilia/v_object/time_zone_data.rb +10 -0
- data/lib/tilia/v_object/time_zone_util.rb +213 -0
- data/lib/tilia/v_object/uuid_util.rb +51 -0
- data/lib/tilia/v_object/v_card_converter.rb +354 -0
- data/lib/tilia/v_object/version.rb +9 -0
- data/lib/tilia/v_object/writer.rb +56 -0
- data/lib/tilia/v_object.rb +45 -0
- data/lib/tilia/vobject.rb +1 -0
- data/resources/schema/xcal.rng +1192 -0
- data/resources/schema/xcard.rng +388 -0
- data/test/test_helper.rb +56 -0
- data/test/v_object/attach_issue_test.rb +19 -0
- data/test/v_object/birthday_calendar_generator_test.rb +463 -0
- data/test/v_object/cli_mock.rb +19 -0
- data/test/v_object/cli_test.rb +460 -0
- data/test/v_object/component/available_test.rb +59 -0
- data/test/v_object/component/v_alarm_test.rb +160 -0
- data/test/v_object/component/v_availability_test.rb +388 -0
- data/test/v_object/component/v_calendar_test.rb +646 -0
- data/test/v_object/component/v_card_test.rb +258 -0
- data/test/v_object/component/v_event_test.rb +85 -0
- data/test/v_object/component/v_free_busy_test.rb +59 -0
- data/test/v_object/component/v_journal_test.rb +85 -0
- data/test/v_object/component/v_time_zone_test.rb +47 -0
- data/test/v_object/component/v_todo_test.rb +172 -0
- data/test/v_object/component_test.rb +419 -0
- data/test/v_object/date_time_parser_test.rb +526 -0
- data/test/v_object/document_test.rb +71 -0
- data/test/v_object/element_list_test.rb +27 -0
- data/test/v_object/em_client_test.rb +53 -0
- data/test/v_object/empty_parameter_test.rb +65 -0
- data/test/v_object/empty_value_issue_test.rb +25 -0
- data/test/v_object/fake_component.rb +21 -0
- data/test/v_object/free_busy_data_test.rb +285 -0
- data/test/v_object/free_busy_generator_test.rb +637 -0
- data/test/v_object/google_colon_escaping_test.rb +27 -0
- data/test/v_object/i_calendar/attach_parse_test.rb +24 -0
- data/test/v_object/i_tip/broker_attendee_reply_test.rb +1042 -0
- data/test/v_object/i_tip/broker_delete_event_test.rb +175 -0
- data/test/v_object/i_tip/broker_new_event_test.rb +440 -0
- data/test/v_object/i_tip/broker_process_message_test.rb +153 -0
- data/test/v_object/i_tip/broker_process_reply_test.rb +402 -0
- data/test/v_object/i_tip/broker_tester.rb +71 -0
- data/test/v_object/i_tip/broker_update_event_test.rb +763 -0
- data/test/v_object/i_tip/evolution_test.rb +2644 -0
- data/test/v_object/i_tip/message_test.rb +25 -0
- data/test/v_object/issue153.vcf +352 -0
- data/test/v_object/issue153_test.rb +12 -0
- data/test/v_object/issue26_test.rb +25 -0
- data/test/v_object/issue36_work_around_test.rb +37 -0
- data/test/v_object/issue40_test.rb +26 -0
- data/test/v_object/issue64.vcf +351 -0
- data/test/v_object/issue64_test.rb +17 -0
- data/test/v_object/issue96_test.rb +22 -0
- data/test/v_object/issue_undefined_index_test.rb +24 -0
- data/test/v_object/j_cal_test.rb +150 -0
- data/test/v_object/j_card_test.rb +192 -0
- data/test/v_object/line_folding_issue_test.rb +19 -0
- data/test/v_object/mock_document.rb +6 -0
- data/test/v_object/parameter_test.rb +109 -0
- data/test/v_object/parser/json_test.rb +370 -0
- data/test/v_object/parser/mime_dir_test.rb +14 -0
- data/test/v_object/parser/quoted_printable_test.rb +78 -0
- data/test/v_object/parser/xml_test.rb +2563 -0
- data/test/v_object/property/binary_test.rb +12 -0
- data/test/v_object/property/boolean_test.rb +18 -0
- data/test/v_object/property/compound_test.rb +43 -0
- data/test/v_object/property/float_test.rb +20 -0
- data/test/v_object/property/i_calendar/cal_address_test.rb +26 -0
- data/test/v_object/property/i_calendar/date_time_test.rb +303 -0
- data/test/v_object/property/i_calendar/duration_test.rb +14 -0
- data/test/v_object/property/i_calendar/recur_test.rb +39 -0
- data/test/v_object/property/text_test.rb +81 -0
- data/test/v_object/property/v_card/date_and_or_time_test.rb +205 -0
- data/test/v_object/property/v_card/language_tag_test.rb +35 -0
- data/test/v_object/property_test.rb +338 -0
- data/test/v_object/reader_test.rb +403 -0
- data/test/v_object/recur/event_iterator/by_month_in_daily_test.rb +52 -0
- data/test/v_object/recur/event_iterator/by_set_pos_hang_test.rb +55 -0
- data/test/v_object/recur/event_iterator/expand_floating_times_test.rb +109 -0
- data/test/v_object/recur/event_iterator/fifth_tuesday_problem_test.rb +45 -0
- data/test/v_object/recur/event_iterator/incorrect_expand_test.rb +53 -0
- data/test/v_object/recur/event_iterator/infinite_loop_problem_test.rb +75 -0
- data/test/v_object/recur/event_iterator/issue48_test.rb +43 -0
- data/test/v_object/recur/event_iterator/issue50_test.rb +123 -0
- data/test/v_object/recur/event_iterator/main_test.rb +1222 -0
- data/test/v_object/recur/event_iterator/missing_overridden_test.rb +55 -0
- data/test/v_object/recur/event_iterator/no_instances_test.rb +32 -0
- data/test/v_object/recur/event_iterator/override_first_event_test.rb +106 -0
- data/test/v_object/recur/r_date_iterator_test.rb +44 -0
- data/test/v_object/recur/r_rule_iterator_test.rb +608 -0
- data/test/v_object/recurrence_iterator/UntilRespectsTimezoneTest.ics +39 -0
- data/test/v_object/slash_r_test.rb +15 -0
- data/test/v_object/splitter/i_calendar_test.rb +299 -0
- data/test/v_object/splitter/v_card_test.rb +173 -0
- data/test/v_object/string_util_test.rb +37 -0
- data/test/v_object/test_case.rb +42 -0
- data/test/v_object/time_zone_util_test.rb +271 -0
- data/test/v_object/uuid_util_test.rb +18 -0
- data/test/v_object/v_card21_test.rb +43 -0
- data/test/v_object/v_card_converter_test.rb +419 -0
- data/test/v_object/version_test.rb +15 -0
- data/test/v_object/writer_test.rb +33 -0
- data/tilia-vobject.gemspec +17 -0
- metadata +308 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Component
|
4
|
+
# VAlarm component.
|
5
|
+
#
|
6
|
+
# This component contains some additional functionality specific for VALARMs.
|
7
|
+
class VAlarm < Component
|
8
|
+
# Returns a DateTime object when this alarm is going to trigger.
|
9
|
+
#
|
10
|
+
# This ignores repeated alarm, only the first trigger is returned.
|
11
|
+
#
|
12
|
+
# @return DateTimeImmutable
|
13
|
+
def effective_trigger_time
|
14
|
+
trigger = self['TRIGGER']
|
15
|
+
if !trigger.key?('VALUE') || trigger['VALUE'].to_s.upcase == 'DURATION'
|
16
|
+
trigger_duration = DateTimeParser.parse_duration(self['TRIGGER'])
|
17
|
+
related = (trigger.key?('RELATED') && trigger['RELATED'].to_s.upcase == 'END') ? 'END' : 'START'
|
18
|
+
|
19
|
+
parent_component = parent
|
20
|
+
if related == 'START'
|
21
|
+
if parent_component.name == 'VTODO'
|
22
|
+
prop_name = 'DUE'
|
23
|
+
else
|
24
|
+
prop_name = 'DTSTART'
|
25
|
+
end
|
26
|
+
|
27
|
+
effective_trigger = parent_component[prop_name].date_time
|
28
|
+
effective_trigger += trigger_duration
|
29
|
+
else
|
30
|
+
if parent_component.name == 'VTODO'
|
31
|
+
end_prop = 'DUE'
|
32
|
+
elsif parent_component.name == 'VEVENT'
|
33
|
+
end_prop = 'DTEND'
|
34
|
+
else
|
35
|
+
fail 'time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT'
|
36
|
+
end
|
37
|
+
|
38
|
+
if parent_component.key?(end_prop)
|
39
|
+
effective_trigger = parent_component[end_prop].date_time
|
40
|
+
effective_trigger += trigger_duration
|
41
|
+
elsif parent_component.key?('DURATION')
|
42
|
+
effective_trigger = parent_component['DTSTART'].date_time
|
43
|
+
duration = DateTimeParser.parse_duration(parent_component['DURATION'])
|
44
|
+
effective_trigger += duration
|
45
|
+
effective_trigger += trigger_duration
|
46
|
+
else
|
47
|
+
effective_trigger = parent_component['DTSTART'].date_time
|
48
|
+
effective_trigger += trigger_duration
|
49
|
+
end
|
50
|
+
end
|
51
|
+
else
|
52
|
+
effective_trigger = trigger.date_time
|
53
|
+
end
|
54
|
+
|
55
|
+
effective_trigger
|
56
|
+
end
|
57
|
+
|
58
|
+
# Returns true or false depending on if the event falls in the specified
|
59
|
+
# time-range. This is used for filtering purposes.
|
60
|
+
#
|
61
|
+
# The rules used to determine if an event falls within the specified
|
62
|
+
# time-range is based on the CalDAV specification.
|
63
|
+
#
|
64
|
+
# @param DateTime start
|
65
|
+
# @param DateTime ending
|
66
|
+
#
|
67
|
+
# @return bool
|
68
|
+
def in_time_range?(start, ending)
|
69
|
+
effective_trigger = effective_trigger_time
|
70
|
+
|
71
|
+
if key?('DURATION')
|
72
|
+
duration = DateTimeParser.parse_duration(self['DURATION'])
|
73
|
+
repeat = self['repeat']
|
74
|
+
repeat = 1 if repeat.blank?
|
75
|
+
|
76
|
+
occurrence = effective_trigger
|
77
|
+
repeat.to_s.to_i.times do |_i|
|
78
|
+
return true if start <= occurrence && ending > occurrence
|
79
|
+
occurrence += duration
|
80
|
+
end
|
81
|
+
return false
|
82
|
+
else
|
83
|
+
start <= effective_trigger && ending > effective_trigger
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
# A simple list of validation rules.
|
88
|
+
#
|
89
|
+
# This is simply a list of properties, and how many times they either
|
90
|
+
# must or must not appear.
|
91
|
+
#
|
92
|
+
# Possible values per property:
|
93
|
+
# * 0 - Must not appear.
|
94
|
+
# * 1 - Must appear exactly once.
|
95
|
+
# * + - Must appear at least once.
|
96
|
+
# * * - Can appear any number of times.
|
97
|
+
# * ? - May appear, but not more than once.
|
98
|
+
#
|
99
|
+
# @var array
|
100
|
+
def validation_rules
|
101
|
+
{
|
102
|
+
'ACTION' => 1,
|
103
|
+
'TRIGGER' => 1,
|
104
|
+
|
105
|
+
'DURATION' => '?',
|
106
|
+
'REPEAT' => '?',
|
107
|
+
|
108
|
+
'ATTACH' => '?'
|
109
|
+
}
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,128 @@
|
|
1
|
+
module Tilia
|
2
|
+
module VObject
|
3
|
+
class Component
|
4
|
+
# The VAvailability component.
|
5
|
+
#
|
6
|
+
# This component adds functionality to a component, specific for VAVAILABILITY
|
7
|
+
# components.
|
8
|
+
class VAvailability < Component
|
9
|
+
# Returns true or false depending on if the event falls in the specified
|
10
|
+
# time-range. This is used for filtering purposes.
|
11
|
+
#
|
12
|
+
# The rules used to determine if an event falls within the specified
|
13
|
+
# time-range is based on:
|
14
|
+
#
|
15
|
+
# https://tools.ietf.org/html/draft-daboo-calendar-availability-05#section-3.1
|
16
|
+
#
|
17
|
+
# @param DateTimeInterface start
|
18
|
+
# @param DateTimeInterface ending
|
19
|
+
#
|
20
|
+
# @return bool
|
21
|
+
def in_time_range?(start, ending)
|
22
|
+
(effective_start, effective_end) = effective_start_end
|
23
|
+
(effective_start.nil? || start < effective_end) &&
|
24
|
+
(effective_end.nil? || ending > effective_start)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Returns the 'effective start' and 'effective end' of this VAVAILABILITY
|
28
|
+
# component.
|
29
|
+
#
|
30
|
+
# We use the DTSTART and DTEND or DURATION to determine this.
|
31
|
+
#
|
32
|
+
# The returned value is an array containing DateTimeImmutable instances.
|
33
|
+
# If either the start or end is 'unbounded' its value will be null
|
34
|
+
# instead.
|
35
|
+
#
|
36
|
+
# @return array
|
37
|
+
def effective_start_end
|
38
|
+
effective_start = nil
|
39
|
+
effective_end = nil
|
40
|
+
|
41
|
+
effective_start = self['DTSTART'].date_time if key?('DTSTART')
|
42
|
+
|
43
|
+
if key?('DTEND')
|
44
|
+
effective_end = self['DTEND'].date_time
|
45
|
+
elsif effective_start && key?('DURATION')
|
46
|
+
effective_end = effective_start + Tilia::VObject::DateTimeParser.parse_duration(self['DURATION'])
|
47
|
+
end
|
48
|
+
|
49
|
+
[effective_start, effective_end]
|
50
|
+
end
|
51
|
+
|
52
|
+
# A simple list of validation rules.
|
53
|
+
#
|
54
|
+
# This is simply a list of properties, and how many times they either
|
55
|
+
# must or must not appear.
|
56
|
+
#
|
57
|
+
# Possible values per property:
|
58
|
+
# * 0 - Must not appear.
|
59
|
+
# * 1 - Must appear exactly once.
|
60
|
+
# * + - Must appear at least once.
|
61
|
+
# * * - Can appear any number of times.
|
62
|
+
# * ? - May appear, but not more than once.
|
63
|
+
#
|
64
|
+
# @var array
|
65
|
+
def validation_rules
|
66
|
+
{
|
67
|
+
'UID' => 1,
|
68
|
+
'DTSTAMP' => 1,
|
69
|
+
|
70
|
+
'BUSYTYPE' => '?',
|
71
|
+
'CLASS' => '?',
|
72
|
+
'CREATED' => '?',
|
73
|
+
'DESCRIPTION' => '?',
|
74
|
+
'DTSTART' => '?',
|
75
|
+
'LAST-MODIFIED' => '?',
|
76
|
+
'ORGANIZER' => '?',
|
77
|
+
'PRIORITY' => '?',
|
78
|
+
'SEQUENCE' => '?',
|
79
|
+
'SUMMARY' => '?',
|
80
|
+
'URL' => '?',
|
81
|
+
'DTEND' => '?',
|
82
|
+
'DURATION' => '?',
|
83
|
+
|
84
|
+
'CATEGORIES' => '*',
|
85
|
+
'COMMENT' => '*',
|
86
|
+
'CONTACT' => '*'
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
# Validates the node for correctness.
|
91
|
+
#
|
92
|
+
# The following options are supported:
|
93
|
+
# Node::REPAIR - May attempt to automatically repair the problem.
|
94
|
+
# Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
|
95
|
+
# Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
|
96
|
+
#
|
97
|
+
# This method returns an array with detected problems.
|
98
|
+
# Every element has the following properties:
|
99
|
+
#
|
100
|
+
# * level - problem level.
|
101
|
+
# * message - A human-readable string describing the issue.
|
102
|
+
# * node - A reference to the problematic node.
|
103
|
+
#
|
104
|
+
# The level means:
|
105
|
+
# 1 - The issue was repaired (only happens if REPAIR was turned on).
|
106
|
+
# 2 - A warning.
|
107
|
+
# 3 - An error.
|
108
|
+
#
|
109
|
+
# @param int options
|
110
|
+
#
|
111
|
+
# @return array
|
112
|
+
def validate(options = 0)
|
113
|
+
result = super(options)
|
114
|
+
|
115
|
+
if key?('DTEND') && key?('DURATION')
|
116
|
+
result << {
|
117
|
+
'level' => 3,
|
118
|
+
'message' => 'DTEND and DURATION cannot both be present',
|
119
|
+
'node' => self
|
120
|
+
}
|
121
|
+
end
|
122
|
+
|
123
|
+
result
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|