Class: Itonoko::XML::Text

Inherits:
Node
  • Object
show all
Defined in:
lib/itonoko/xml/text.rb

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::EMPTY_ATTRS, Node::EMPTY_CHILDREN, Node::PROCESSING_INSTRUCTION_NODE, Node::TEXT_NODE

Instance Attribute Summary collapse

Attributes inherited from Node

#children, #document, #node_type, #parent

Instance Method Summary collapse

Methods inherited from Node

#==, #[], #[]=, #add_child, #add_next_sibling, #add_previous_sibling, #ancestors, #append_child, #at, #at_css, #at_xpath, #attribute, #attribute_nodes, #attributes, #cdata_node?, #child, #comment?, #css, #description, #document?, #element?, #element_children, #fragment?, #get_attribute, #has_attribute?, #inner_html, #inner_html=, #inspect, #keys, #matches?, #name, #next_element, #next_sibling, #prepend_child, #previous_element, #previous_sibling, #remove, #remove_attribute, #replace, #root, #search, #set_attribute, #text=, #text?, #xpath

Constructor Details

#initialize(content, document = nil) ⇒ Text

Returns a new instance of Text.



8
9
10
11
12
13
14
15
16
17
# File 'lib/itonoko/xml/text.rb', line 8

def initialize(content, document = nil)
  # Bypass Node#initialize to avoid allocating unused @children / @attributes arrays.
  @node_type  = TEXT_NODE
  @node_name  = "#text"
  @document   = document
  @parent     = nil
  @children   = EMPTY_CHILDREN
  @attributes = EMPTY_ATTRS
  @content    = content.to_s
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



6
7
8
# File 'lib/itonoko/xml/text.rb', line 6

def content
  @content
end

Instance Method Details

#_collect_text(buf) ⇒ Object



23
24
25
# File 'lib/itonoko/xml/text.rb', line 23

def _collect_text(buf)
  buf << @content
end

#node_nameObject



36
37
38
# File 'lib/itonoko/xml/text.rb', line 36

def node_name
  "#text"
end

#textObject



19
20
21
# File 'lib/itonoko/xml/text.rb', line 19

def text
  @content
end

#to_htmlObject Also known as: to_s



27
28
29
# File 'lib/itonoko/xml/text.rb', line 27

def to_html
  escape_text(@content)
end

#to_xml(_options = {}) ⇒ Object



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

def to_xml(_options = {})
  escape_text(@content)
end