Class: Oga::XML::Text

Inherits:
CharacterNode show all
Defined in:
lib/oga/xml/text.rb

Overview

Class containing information about a single text node. Text nodes don't have any children, attributes and the likes; just text.

Instance Attribute Summary

Attributes inherited from Node

#node_set

Instance Method Summary collapse

Methods inherited from CharacterNode

#inspect

Methods inherited from Node

#after, #before, #children, #children=, #html?, #next, #next_element, #parent, #previous, #previous_element, #remove, #replace, #root_node, #xml?

Methods included from Traversal

#each_node

Constructor Details

#initialize(*args) ⇒ Text

Returns a new instance of Text.



8
9
10
11
12
# File 'lib/oga/xml/text.rb', line 8

def initialize(*args)
  super

  @decoded = false
end

Instance Method Details

#textString

Returns the text as a String. Upon the first call any XML/HTML entities are decoded.

Returns:

  • (String)


28
29
30
31
32
33
34
35
# File 'lib/oga/xml/text.rb', line 28

def text
  if decode_entities?
    @text    = EntityDecoder.try_decode(@text, html?)
    @decoded = true
  end

  @text
end

#text=(value) ⇒ Object

Parameters:

  • value (String)


17
18
19
20
# File 'lib/oga/xml/text.rb', line 17

def text=(value)
  @decoded = false
  @text    = value
end

#to_xmlObject

See Also:

  • Oga::XML::Text.[Oga[Oga::XML[Oga::XML::CharacterNode[Oga::XML::CharacterNode#to_xml]


40
41
42
43
44
# File 'lib/oga/xml/text.rb', line 40

def to_xml
  return super if inside_literal_html?

  Entities.encode(super)
end