Class: Oga::XML::CharacterNode

Inherits:
Node
  • Object
show all
Defined in:
lib/oga/xml/character_node.rb

Overview

Base class for nodes that represent a text-like value such as Text and Comment nodes.

Direct Known Subclasses

Cdata, Comment, ProcessingInstruction, Text

Instance Attribute Summary collapse

Attributes inherited from Node

#node_set

Instance Method Summary collapse

Methods inherited from Node

#after, #before, #children, #children=, #next, #next_element, #parent, #previous, #previous_element, #remove, #root_node

Methods included from Traversal

#each_node

Constructor Details

#initialize(options = {}) ⇒ CharacterNode

Returns a new instance of CharacterNode

Options Hash (options):

  • :text (String)

    The text of the node.


18
19
20
21
22
# File 'lib/oga/xml/character_node.rb', line 18

def initialize(options = {})
  super

  @text = options[:text]
end

Instance Attribute Details

#textString


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/oga/xml/character_node.rb', line 10

class CharacterNode < Node
  attr_accessor :text

  ##
  # @param [Hash] options
  #
  # @option options [String] :text The text of the node.
  #
  def initialize(options = {})
    super

    @text = options[:text]
  end

  ##
  # @return [String]
  #
  def to_xml
    return text.to_s
  end

  ##
  # @return [String]
  #
  def inspect
    return "#{self.class.to_s.split('::').last}(#{text.inspect})"
  end
end

Instance Method Details

#inspectString


34
35
36
# File 'lib/oga/xml/character_node.rb', line 34

def inspect
  return "#{self.class.to_s.split('::').last}(#{text.inspect})"
end

#to_xmlString


27
28
29
# File 'lib/oga/xml/character_node.rb', line 27

def to_xml
  return text.to_s
end