Class: Tilia::VObject::Node
- Inherits:
-
Object
- Object
- Tilia::VObject::Node
- 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.
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
-
#iterator ⇒ ElementList
Returns the iterator for this object.
-
#parent ⇒ Node
Reference to the parent object, if this is not the top object.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#[](offset) ⇒ mixed
Gets an item through ArrayAccess.
-
#[]=(offset, value) ⇒ void
Sets an item through ArrayAccess.
-
#delete(offset) ⇒ void
Sets an item through ArrayAccess.
-
#destroy ⇒ void
Call this method on a document if you’re done using it.
- #each ⇒ Object
-
#initialize ⇒ Node
constructor
A new instance of Node.
-
#json_serialize ⇒ array
This method returns an array, with the representation as it should be encoded in JSON.
-
#key?(offset) ⇒ Boolean
Checks if an item exists through ArrayAccess.
-
#serialize ⇒ String
Serializes the node into a mimedir format.
-
#size ⇒ Fixnum
(also: #length, #count)
Returns the number of elements.
-
#validate(_options = 0) ⇒ array
Validates the node for correctness.
-
#xml_serialize(writer) ⇒ void
This method serializes the data into XML.
Constructor Details
#initialize ⇒ Node
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
#iterator ⇒ ElementList
Returns the iterator for this object.
93 94 95 96 97 |
# File 'lib/tilia/v_object/node.rb', line 93 def iterator return @iterator if @iterator ElementList.new([self]) end |
#parent ⇒ Node
Reference to the parent object, if this is not the top object.
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
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
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
162 163 164 165 |
# File 'lib/tilia/v_object/node.rb', line 162 def delete(offset) iterator = self.iterator iterator.delete(offset) end |
#destroy ⇒ void
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 |
#each ⇒ Object
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_serialize ⇒ array
This method returns an array, with the representation as it should be encoded in JSON. This is used to create jCard or jCal documents.
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
125 126 127 128 |
# File 'lib/tilia/v_object/node.rb', line 125 def key?(offset) iterator = self.iterator iterator.key?(offset) end |
#serialize ⇒ String
Serializes the node into a mimedir format.
36 37 |
# File 'lib/tilia/v_object/node.rb', line 36 def serialize end |
#size ⇒ Fixnum Also known as: length, count
Returns the number of elements.
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.
86 87 88 |
# File 'lib/tilia/v_object/node.rb', line 86 def validate( = 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.
52 53 |
# File 'lib/tilia/v_object/node.rb', line 52 def xml_serialize(writer) end |