Class: Tilia::VObject::Component::VAlarm
- Inherits:
-
Tilia::VObject::Component
- Object
- Node
- Tilia::VObject::Component
- Tilia::VObject::Component::VAlarm
- Defined in:
- lib/tilia/v_object/component/v_alarm.rb
Overview
VAlarm component.
This component contains some additional functionality specific for VALARMs.
Constant Summary
Constants inherited from Node
Node::PROFILE_CALDAV, Node::PROFILE_CARDDAV, Node::REPAIR
Instance Attribute Summary
Attributes inherited from Tilia::VObject::Component
Attributes inherited from Node
Instance Method Summary collapse
-
#effective_trigger_time ⇒ Time
Returns a DateTime object when this alarm is going to trigger.
-
#in_time_range?(start, ending) ⇒ Boolean
Returns true or false depending on if the event falls in the specified time-range.
-
#validation_rules ⇒ array
A simple list of validation rules.
Methods inherited from Tilia::VObject::Component
#[], #[]=, #add, #children, #components, #delete, #destroy, #initialize, #initialize_copy, #json_serialize, #key?, #remove, #select, #serialize, #to_s, #validate, #xml_serialize
Methods inherited from Node
#==, #[], #[]=, #delete, #destroy, #each, #initialize, #json_serialize, #key?, #serialize, #size, #validate, #xml_serialize
Constructor Details
This class inherits a constructor from Tilia::VObject::Component
Instance Method Details
#effective_trigger_time ⇒ Time
Returns a DateTime object when this alarm is going to trigger.
This ignores repeated alarm, only the first trigger is returned.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tilia/v_object/component/v_alarm.rb', line 13 def effective_trigger_time trigger = self['TRIGGER'] if !trigger.key?('VALUE') || trigger['VALUE'].to_s.upcase == 'DURATION' trigger_duration = DateTimeParser.parse_duration(self['TRIGGER']) = (trigger.key?('RELATED') && trigger['RELATED'].to_s.upcase == 'END') ? 'END' : 'START' parent_component = parent if == 'START' if parent_component.name == 'VTODO' prop_name = 'DUE' else prop_name = 'DTSTART' end effective_trigger = parent_component[prop_name].date_time effective_trigger += trigger_duration else if parent_component.name == 'VTODO' end_prop = 'DUE' elsif parent_component.name == 'VEVENT' end_prop = 'DTEND' else fail InvalidDataException, 'time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT' end if parent_component.key?(end_prop) effective_trigger = parent_component[end_prop].date_time effective_trigger += trigger_duration elsif parent_component.key?('DURATION') effective_trigger = parent_component['DTSTART'].date_time duration = DateTimeParser.parse_duration(parent_component['DURATION']) effective_trigger += duration effective_trigger += trigger_duration else effective_trigger = parent_component['DTSTART'].date_time effective_trigger += trigger_duration end end else effective_trigger = trigger.date_time end effective_trigger end |
#in_time_range?(start, ending) ⇒ Boolean
Returns true or false depending on if the event falls in the specified time-range. This is used for filtering purposes.
The rules used to determine if an event falls within the specified time-range is based on the CalDAV specification.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/tilia/v_object/component/v_alarm.rb', line 68 def in_time_range?(start, ending) effective_trigger = effective_trigger_time if key?('DURATION') duration = DateTimeParser.parse_duration(self['DURATION']) repeat = self['REPEAT'].to_s.to_i repeat = 1 if repeat == 0 occurrence = effective_trigger return true if start <= occurrence && ending > occurrence repeat.times do |_i| occurrence += duration return true if start <= occurrence && ending > occurrence end return false else start <= effective_trigger && ending > effective_trigger end end |
#validation_rules ⇒ array
A simple list of validation rules.
This is simply a list of properties, and how many times they either must or must not appear.
Possible values per property:
* 0 - Must not appear.
* 1 - Must appear exactly once.
* + - Must appear at least once.
* * - Can appear any number of times.
* ? - May appear, but not more than once.
It is also possible to specify defaults and severity levels for violating the rule.
See the VEVENT implementation for getValidationRules for a more complex example.
90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/tilia/v_object/component/v_alarm.rb', line 90 def validation_rules { 'ACTION' => 1, 'TRIGGER' => 1, 'DURATION' => '?', 'REPEAT' => '?', 'ATTACH' => '?' } end |