Class: Tilia::VObject::Component::VTodo

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

Overview

VTodo component.

This component contains some additional functionality specific for VTODOs.

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

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

Parameters:

  • start (Time)
  • end (Time)

Returns:

  • (Boolean)


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

def in_time_range?(start, ending)
  dtstart = key?('DTSTART') ? self['DTSTART'].date_time : nil
  duration = key?('DURATION') ? Tilia::VObject::DateTimeParser.parse_duration(self['DURATION']) : nil
  due = key?('DUE') ? self['DUE'].date_time : nil
  completed = key?('COMPLETED') ? self['COMPLETED'].date_time : nil
  created = key?('CREATED') ? self['CREATED'].date_time : nil

  if dtstart
    if duration
      effective_ending = dtstart + duration
      return start <= effective_ending && ending > dtstart
    elsif due
      return (start < due || start <= dtstart) && (ending > dtstart || ending >= due)
    else
      return start <= dtstart && ending > dtstart
    end
  end

  return start < due && ending >= due if due

  if completed && created
    return (start <= created || start <= completed) && (ending >= created || ending >= completed)
  end

  return (start <= completed && ending >= completed) if completed

  return (ending > created) if created

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


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/tilia/v_object/component/v_todo.rb', line 90

def validate(options = 0)
  result = super(options)
  if key?('DUE') && key?('DTSTART')
    due = self['DUE']
    dt_start = self['DTSTART']

    if due.value_type != dt_start.value_type
      result << {
        'level'   => 3,
        'message' => 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART',
        'node'    => due
      }
    elsif due.date_time < dt_start.date_time
      result << {
        'level'   => 3,
        'message' => 'DUE must occur after DTSTART',
        'node'    => due
      }
    end
  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)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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_todo.rb', line 50

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

    'CLASS'         => '?',
    'COMPLETED'     => '?',
    'CREATED'       => '?',
    'DESCRIPTION'   => '?',
    'DTSTART'       => '?',
    'GEO'           => '?',
    'LAST-MODIFIED' => '?',
    'LOCATION'      => '?',
    'ORGANIZER'     => '?',
    'PERCENT'       => '?',
    'PRIORITY'      => '?',
    'RECURRENCE-ID' => '?',
    'SEQUENCE'      => '?',
    'STATUS'        => '?',
    'SUMMARY'       => '?',
    'URL'           => '?',

    'RRULE'    => '?',
    'DUE'      => '?',
    'DURATION' => '?',

    'ATTACH'         => '*',
    'ATTENDEE'       => '*',
    'CATEGORIES'     => '*',
    'COMMENT'        => '*',
    'CONTACT'        => '*',
    'EXDATE'         => '*',
    'REQUEST-STATUS' => '*',
    'RELATED-TO'     => '*',
    'RESOURCES'      => '*',
    'RDATE'          => '*'
  }
end