Class: Tilia::VObject::Component::Available

Inherits:
Tilia::VObject::Component show all
Defined in:
lib/tilia/v_object/component/available.rb

Overview

The Available sub-component.

This component adds functionality to a component, specific for AVAILABLE components.

Constant Summary

Constants inherited from Node

Node::PROFILE_CALDAV, Node::PROFILE_CARDDAV, Node::REPAIR

Instance Attribute Summary

Attributes inherited from Tilia::VObject::Component

#name

Attributes inherited from Node

#iterator, #parent

Instance Method Summary collapse

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_endArray<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.

Returns:

  • (Array<Time, nil>)


19
20
21
22
23
24
25
26
27
28
# File 'lib/tilia/v_object/component/available.rb', line 19

def effective_start_end
  effective_start = self['DTSTART'].date_time
  if key?('DTEND')
    effective_end = self['DTEND'].date_time
  else
    effective_end = effective_start + DateTimeParser.parse_duration(self['DURATION'])
  end

  [effective_start, effective_end]
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.

Parameters:

  • options (Fixnum) (defaults to: 0)

Returns:

  • (array)


58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tilia/v_object/component/available.rb', line 58

def validate(options = 0)
  result = super(options)

  if key?('DTEND') && key?('DURATION')
    result << {
      'level'   => 3,
      'message' => 'DTEND and DURATION cannot both be present',
      'node'    => self
    }
  end

  result
end

#validation_rulesarray

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.

Returns:

  • (array)


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
# File 'lib/tilia/v_object/component/available.rb', line 31

def validation_rules
  {
    'UID'     => 1,
    'DTSTART' => 1,
    'DTSTAMP' => 1,

    'DTEND'    => '?',
    'DURATION' => '?',

    'CREATED'       => '?',
    'DESCRIPTION'   => '?',
    'LAST-MODIFIED' => '?',
    'RECURRENCE-ID' => '?',
    'RRULE'         => '?',
    'SUMMARY'       => '?',

    'CATEGORIES' => '*',
    'COMMENT'    => '*',
    'CONTACT'    => '*',
    'EXDATE'     => '*',
    'RDATE'      => '*',

    'AVAILABLE' => '*'
  }
end