Class: VCDOM::MiniDOM::CharacterData

Inherits:
Node
  • Object
show all
Includes:
ModChildNode
Defined in:
lib/vcdom/minidom/character_data.rb

Direct Known Subclasses

CDATASection, Comment, Text

Constant Summary

Constants inherited from Node

Node::ATTRIBUTE_NODE, Node::CDATA_SECTION_NODE, Node::COMMENT_NODE, Node::DOCUMENT_FRAGMENT_NODE, Node::DOCUMENT_NODE, Node::DOCUMENT_TYPE_NODE, Node::ELEMENT_NODE, Node::ENTITY_NODE, Node::ENTITY_REFERENCE_NODE, Node::NOTATION_NODE, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE

Instance Method Summary collapse

Methods included from ModChildNode

#init_mod_child_node, #next_sibling, #parent_node, #previous_sibling

Methods inherited from Node

#append_child, #attributes, #child_nodes, #first_child, #has_attributes, #has_child_nodes, #insert_before, #last_child, #local_name, #namespace_uri, #next_sibling, #owner_document, #parent_node, #prefix, #prefix=, #previous_sibling, #remove_child, #replace_child, #text_content, #text_content=

Constructor Details

#initialize(owner_document, value) ⇒ CharacterData

Returns a new instance of CharacterData.



225
226
227
228
229
# File 'lib/vcdom/minidom/character_data.rb', line 225

def initialize( owner_document, value )
  super( owner_document )
  init_mod_child_node()
  @data = value
end

Instance Method Details

#append_data(arg) ⇒ Object

appendData

Append the string to the end of the character data of the node. 
Upon success, data provides access to the concatenation of data and the DOMString specified.

Parameters
  arg of type DOMString
    The DOMString to append.
Exceptions
  DOMException
    NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
No Return Value


89
90
91
92
93
94
95
96
# File 'lib/vcdom/minidom/character_data.rb', line 89

def append_data( arg )
  if self.is_readonly then
    raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR, 
            'This node is readonly.' )
  end
  @data = @data + arg
  return nil
end

#dataObject Also known as: node_value

data of type DOMString

The character data of the node that implements this interface. 
The DOM implementation may not put arbitrary limits on the amount of 
data that may be stored in a CharacterData node. 
However, implementation limits may mean that the entirety of a node's 
data may not fit into a single DOMString. 
In such cases, the user may call substringData to retrieve the data in 
appropriately sized pieces.

Exceptions on setting
  DOMException NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
Exceptions on retrieval
  DOMException DOMSTRING_SIZE_ERR: Raised when it would return more characters than fit in a DOMString variable on the implementation platform.


27
28
29
# File 'lib/vcdom/minidom/character_data.rb', line 27

def data
  return @data
end

#data=(value) ⇒ Object Also known as: node_value=



30
31
32
33
34
35
36
# File 'lib/vcdom/minidom/character_data.rb', line 30

def data=( value )
  if self.is_readonly then
    raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR, 
            'This node is readonly.' )
  end
  @data = value
end

#delete_data(offset, count) ⇒ Object

deleteData

Remove a range of 16-bit units from the node. Upon success, data and length 
reflect the change.

Parameters
  offset of type unsigned long
    The offset from which to start removing.
  count of type unsigned long
    The number of 16-bit units to delete. If the sum of offset and count 
    exceeds length then all 16-bit units from offset to the end of the data 
    are deleted.
Exceptions
  DOMException
    INDEX_SIZE_ERR: Raised if the specified offset is negative or greater 
            than the number of 16-bit units in data, or if the specified 
            count is negative.
    NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
No Return Value


116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/vcdom/minidom/character_data.rb', line 116

def delete_data( offset, count )
  if self.is_readonly then
    raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR, 
            'This node is readonly.' )
  end
  begin
    substrs = split( offset, count )
  rescue DOMException => err
    raise DOMException.new( err )
  end
  @data = substrs[0] + substrs[2]
  return nil
end

#insert_data(offset, arg) ⇒ Object

insertData

Insert a string at the specified 16-bit unit offset.

Parameters
  offset of type unsigned long
    The character offset at which to insert.
  arg of type DOMString
    The DOMString to insert.
Exceptions
  DOMException
    INDEX_SIZE_ERR: Raised if the specified offset is negative or greater 
            than the number of 16-bit units in data.
    NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
No Return Value


145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/vcdom/minidom/character_data.rb', line 145

def insert_data( offset, arg )
  if self.is_readonly then
    raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR, 
            'This node is readonly.' )
  end
  begin
    substrs = split( offset )
  rescue DOMException => err
    raise DOMException.new( err )
  end
  @data = substrs[0] + arg + substrs[1]
  return nil
end

#lengthObject

length of type unsigned long, readonly

The number of 16-bit units that are available through data and the substringData method below. 
This may have the value zero, i.e., CharacterData nodes may be empty.


66
67
68
69
70
71
72
73
# File 'lib/vcdom/minidom/character_data.rb', line 66

def length
  count = 0
  while /\A.{#{count}}/mu =~ @data do
    count += 1
  end
  count -= 1
  return count
end

#replace_data(offset, count, arg) ⇒ Object

replaceData

Replace the characters starting at the specified 16-bit unit offset with 
the specified string.

Parameters
  offset of type unsigned long
    The offset from which to start replacing.
  count of type unsigned long
    The number of 16-bit units to replace. If the sum of offset and count 
    exceeds length, then all 16-bit units to the end of the data are replaced; 
    (i.e., the effect is the same as a remove method call with the same range, 
    followed by an append method invocation).
  arg of type DOMString
    The DOMString with which the range must be replaced.
Exceptions
  DOMException
    INDEX_SIZE_ERR: Raised if the specified offset is negative or greater 
            than the number of 16-bit units in data, or if the specified count 
            is negative.
    NO_MODIFICATION_ALLOWED_ERR: Raised if this node is readonly.
No Return Value


181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/vcdom/minidom/character_data.rb', line 181

def replace_data( offset, count, arg )
  if self.is_readonly then
    raise DOMException.new( DOMException::NO_MODIFICATION_ALLOWED_ERR, 
            'This node is readonly.' )
  end
  begin
    substrs = split( offset, count )
  rescue DOMException => err
    raise DOMException.new( err )
  end
  @data = substrs[0] + arg + substrs[2]
  return nil
end

#substring_data(offset, count) ⇒ Object

substringData

Extracts a range of data from the node.

Parameters
  offset of type unsigned long
    Start offset of substring to extract.
  count of type unsigned long
    The number of 16-bit units to extract.
Return Value
  DOMString
    The specified substring. If the sum of offset and count exceeds the length, 
    then all 16-bit units to the end of the data are returned.
Exceptions
  DOMException
    INDEX_SIZE_ERR: Raised if the specified offset is negative or greater than 
            the number of 16-bit units in data, or if the specified count is 
            negative.
    DOMSTRING_SIZE_ERR: Raised if the specified range of text does not fit 
            into a DOMString.


215
216
217
218
219
220
221
222
# File 'lib/vcdom/minidom/character_data.rb', line 215

def substring_data( offset, count )
  begin
    substrs = split( offset, count )
  rescue DOMException => err
    raise DOMException.new( err )
  end
  return substrs[1]
end