Class: Tilia::VObject::Node

Inherits:
Object
  • Object
show all
Includes:
Enumerable, Xml::XmlSerializable
Defined in:
lib/tilia/v_object/node.rb

Overview

A node is the root class for every element in an iCalendar of vCard object.

Direct Known Subclasses

Component, Parameter, Property

Constant Summary collapse

REPAIR =

The following constants are used by the validate method.

If REPAIR is set, the validator will attempt to repair any broken data (if possible).

1
PROFILE_CARDDAV =

If this option is set, the validator will operate on the vcards on the assumption that the vcards need to be valid for CardDAV.

This means for example that the UID is required, whereas it is not for regular vcards.

2
PROFILE_CALDAV =

If this option is set, the validator will operate on iCalendar objects on the assumption that the vcards need to be valid for CalDAV.

This means for example that calendars can only contain objects with identical component types and UIDs.

4

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNode

Returns a new instance of Node.



167
168
169
# File 'lib/tilia/v_object/node.rb', line 167

def initialize
  @root = nil
end

Instance Attribute Details

#iteratorElementList

Returns the iterator for this object.

Returns:



93
94
95
96
97
# File 'lib/tilia/v_object/node.rb', line 93

def iterator
  return @iterator if @iterator

  ElementList.new([self])
end

#parentNode

Reference to the parent object, if this is not the top object.

Returns:



31
32
33
# File 'lib/tilia/v_object/node.rb', line 31

def parent
  @parent
end

Instance Method Details

#==(other) ⇒ Object



176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/tilia/v_object/node.rb', line 176

def ==(other)
  return true if other.__id__ == __id__

  # check class
  return false unless self.class == other.class

  # Instance variables should be the same
  return false unless instance_variables.sort == other.instance_variables.sort

  # compare all instance variables
  instance_variables.each do |var|
    if var == :@root && instance_variable_get(var) == self
      # We are our own root
      return false unless other.instance_variable_get(var) == other
    else
      return false unless instance_variable_get(var) == other.instance_variable_get(var)
    end
  end
  true
end

#[](offset) ⇒ mixed

Gets an item through ArrayAccess.

This method just forwards the request to the inner iterator

Parameters:

  • $offset (Fixnum)

Returns:

  • (mixed)


137
138
139
140
# File 'lib/tilia/v_object/node.rb', line 137

def [](offset)
  iterator = self.iterator
  iterator[offset]
end

#[]=(offset, value) ⇒ void

This method returns an undefined value.

Sets an item through ArrayAccess.

This method just forwards the request to the inner iterator

Parameters:

  • $offset (Fixnum)
  • $value


150
151
152
153
# File 'lib/tilia/v_object/node.rb', line 150

def []=(offset, value)
  iterator = self.iterator
  iterator[offset] = value
end

#delete(offset) ⇒ void

This method returns an undefined value.

Sets an item through ArrayAccess.

This method just forwards the request to the inner iterator

Parameters:

  • $offset (Fixnum)


162
163
164
165
# File 'lib/tilia/v_object/node.rb', line 162

def delete(offset)
  iterator = self.iterator
  iterator.delete(offset)
end

#destroyvoid

This method returns an undefined value.

Call this method on a document if you’re done using it.

It’s intended to remove all circular references, so PHP can easily clean it up.



61
62
63
64
# File 'lib/tilia/v_object/node.rb', line 61

def destroy
  @parent = nil
  @root = nil
end

#eachObject



171
172
173
174
# File 'lib/tilia/v_object/node.rb', line 171

def each
  iterator = self.iterator
  iterator.each { |i| yield(i) }
end

#json_serializearray

This method returns an array, with the representation as it should be encoded in JSON. This is used to create jCard or jCal documents.

Returns:

  • (array)


43
44
# File 'lib/tilia/v_object/node.rb', line 43

def json_serialize
end

#key?(offset) ⇒ Boolean

Checks if an item exists through ArrayAccess.

This method just forwards the request to the inner iterator

Parameters:

  • $offset (Fixnum)

Returns:

  • (Boolean)


125
126
127
128
# File 'lib/tilia/v_object/node.rb', line 125

def key?(offset)
  iterator = self.iterator
  iterator.key?(offset)
end

#serializeString

Serializes the node into a mimedir format.

Returns:

  • (String)


36
37
# File 'lib/tilia/v_object/node.rb', line 36

def serialize
end

#sizeFixnum Also known as: length, count

Returns the number of elements.

Returns:

  • (Fixnum)


111
112
113
114
# File 'lib/tilia/v_object/node.rb', line 111

def size
  it = iterator
  it.size
end

#validate(_options = 0) ⇒ array

Validates the node for correctness.

The following options are supported:

Node::REPAIR - May attempt to automatically repair the problem.

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 - An inconsequential issue
3 - A severe issue.

Parameters:

  • options (Fixnum)

Returns:

  • (array)


86
87
88
# File 'lib/tilia/v_object/node.rb', line 86

def validate(_options = 0)
  []
end

#xml_serialize(writer) ⇒ void

This method returns an undefined value.

This method serializes the data into XML. This is used to create xCard or xCal documents.

Parameters:

  • writer (Xml\Writer)

    XML writer.



52
53
# File 'lib/tilia/v_object/node.rb', line 52

def xml_serialize(writer)
end