Class: Oga::XML::Text
- Inherits:
-
CharacterNode
- Object
- Node
- CharacterNode
- Oga::XML::Text
- 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
Instance Method Summary collapse
-
#decode_entities? ⇒ TrueClass|FalseClass
-
#initialize(*args) ⇒ Text
constructor
A new instance of Text.
-
#inside_literal_html? ⇒ TrueClass|FalseClass
-
#text ⇒ String
Returns the text as a String.
-
#text=(value) ⇒ Object
Methods inherited from CharacterNode
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
Methods included from Traversal
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
32 33 34 |
# File 'lib/oga/xml/text.rb', line 32 def decode_entities? !@decoded && !inside_literal_html? end |
#inside_literal_html? ⇒ 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 |
#text ⇒ String
Returns the text as a String. Upon the first call any XML/HTML entities are decoded.
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
13 14 15 16 |
# File 'lib/oga/xml/text.rb', line 13 def text=(value) @decoded = false @text = value end |