Class: Tilia::VObject::Component::VAvailability
- Inherits:
-
Tilia::VObject::Component
- Object
- Node
- Tilia::VObject::Component
- Tilia::VObject::Component::VAvailability
- Defined in:
- lib/tilia/v_object/component/v_availability.rb
Overview
The VAvailability component.
This component adds functionality to a component, specific for VAVAILABILITY components.
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_start_end ⇒ Array<Time, nil>
Returns the ‘effective start’ and ‘effective end’ of this VAVAILABILITY component.
-
#in_time_range?(start, ending) ⇒ Boolean
Returns true or false depending on if the event falls in the specified time-range.
-
#validate(options = 0) ⇒ array
Validates the node for correctness.
-
#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, #xml_serialize
Methods inherited from Node
#==, #[], #[]=, #delete, #destroy, #each, #initialize, #json_serialize, #key?, #serialize, #size, #xml_serialize
Constructor Details
This class inherits a constructor from Tilia::VObject::Component
Instance Method Details
#effective_start_end ⇒ Array<Time, nil>
Returns the ‘effective start’ and ‘effective end’ of this VAVAILABILITY component.
We use the DTSTART and DTEND or DURATION to determine this.
The returned value is an array containing DateTimeImmutable instances. If either the start or end is ‘unbounded’ its value will be null instead.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/tilia/v_object/component/v_availability.rb', line 37 def effective_start_end effective_start = nil effective_end = nil effective_start = self['DTSTART'].date_time if key?('DTSTART') if key?('DTEND') effective_end = self['DTEND'].date_time elsif effective_start && key?('DURATION') effective_end = effective_start + Tilia::VObject::DateTimeParser.parse_duration(self['DURATION']) end [effective_start, effective_end] 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:
tools.ietf.org/html/draft-daboo-calendar-availability-05#section-3.1
21 22 23 24 25 |
# File 'lib/tilia/v_object/component/v_availability.rb', line 21 def in_time_range?(start, ending) (effective_start, effective_end) = effective_start_end (effective_start.nil? || start < effective_end) && (effective_end.nil? || ending > effective_start) end |
#validate(options = 0) ⇒ array
Validates the node for correctness.
The following options are supported:
Node::REPAIR - May attempt to automatically repair the problem.
Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes.
Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.
This method returns an array with detected problems. Every element has the following properties:
* level - problem level.
* message - A human-readable string describing the issue.
* node - A reference to the problematic node.
The level means:
1 - The issue was repaired (only happens if REPAIR was turned on).
2 - A warning.
3 - An error.
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/tilia/v_object/component/v_availability.rb', line 79 def validate( = 0) result = super() if key?('DTEND') && key?('DURATION') result << { 'level' => 3, 'message' => 'DTEND and DURATION cannot both be present', 'node' => self } end result 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.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/tilia/v_object/component/v_availability.rb', line 53 def validation_rules { 'UID' => 1, 'DTSTAMP' => 1, 'BUSYTYPE' => '?', 'CLASS' => '?', 'CREATED' => '?', 'DESCRIPTION' => '?', 'DTSTART' => '?', 'LAST-MODIFIED' => '?', 'ORGANIZER' => '?', 'PRIORITY' => '?', 'SEQUENCE' => '?', 'SUMMARY' => '?', 'URL' => '?', 'DTEND' => '?', 'DURATION' => '?', 'CATEGORIES' => '*', 'COMMENT' => '*', 'CONTACT' => '*' } end |