Class: Tilia::VObject::Component::VFreeBusy

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

Overview

The VFreeBusy component.

This component adds functionality to a component, specific for VFREEBUSY 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, #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

#free?(start, ending) ⇒ Boolean

Checks based on the contained FREEBUSY information, if a timeslot is available.

Parameters:

  • start (Time)
  • end (Time)

Returns:

  • (Boolean)


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

def free?(start, ending)
  select('FREEBUSY').each do |freebusy|
    # We are only interested in FBTYPE=BUSY (the default),
    # FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE.
    if freebusy.key?('FBTYPE') && freebusy['FBTYPE'].to_s[0...4].upcase != 'BUSY'
      next
    end

    # The freebusy component can hold more than 1 value, separated by
    # commas.
    periods = freebusy.to_s.split(/,/)

    periods.each do |period|
      # Every period is formatted as [start]/[end]. The start is an
      # absolute UTC time, the end may be an absolute UTC time, or
      # duration (relative) value.
      (busy_start, busy_end) = period.split('/')

      busy_start = Tilia::VObject::DateTimeParser.parse(busy_start)
      busy_end = Tilia::VObject::DateTimeParser.parse(busy_end)

      if busy_end.is_a?(ActiveSupport::Duration)
        busy_end = busy_start + busy_end
      end

      return false if start < busy_end && ending > busy_start
    end
  end

  true
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)


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/tilia/v_object/component/v_free_busy.rb', line 49

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

    'CONTACT'   => '?',
    'DTSTART'   => '?',
    'DTEND'     => '?',
    'ORGANIZER' => '?',
    'URL'       => '?',

    'ATTENDEE'       => '*',
    'COMMENT'        => '*',
    'FREEBUSY'       => '*',
    'REQUEST-STATUS' => '*'
  }
end