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

#next, #node_set, #previous

Instance Method Summary collapse

Methods inherited from CharacterNode

#inspect

Methods inherited from Node

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

Methods included from ToXML

#to_xml

Methods included from Traversal

#each_node

Constructor Details

#initialize(*args) ⇒ Text

Returns a new instance of Text



6
7
8
9
10
# File 'lib/oga/xml/text.rb', line 6

def initialize(*args)
  super

  @decoded = false
end

Instance Method Details

#decode_entities?TrueClass|FalseClass

Returns:

  • (TrueClass|FalseClass)


32
33
34
# File 'lib/oga/xml/text.rb', line 32

def decode_entities?
  !@decoded && !inside_literal_html?
end

#inside_literal_html?TrueClass|FalseClass

Returns:

  • (TrueClass|FalseClass)


37
38
39
40
41
# File 'lib/oga/xml/text.rb', line 37

def inside_literal_html?
  node = parent

  node && html? && node.literal_html_name?
end

#textString

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

Returns:

  • (String)


22
23
24
25
26
27
28
29
# File 'lib/oga/xml/text.rb', line 22

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

  @text
end

#text=(value) ⇒ Object

Parameters:

  • value (String)


13
14
15
16
# File 'lib/oga/xml/text.rb', line 13

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