Class: XMLCodec::XMLTextElement

Inherits:
Object
  • Object
show all
Defined in:
lib/subelements.rb

Overview

A simple element that has only text inside. This is used inside XMLSubElements to be able to directly add strings to it and have them be treated as XML text elements.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(string) ⇒ XMLTextElement

Create a new element for the given string.



9
10
11
# File 'lib/subelements.rb', line 9

def initialize(string)
  @value = XMLCodec::XMLUtils::escape_xml(string)
end

Instance Attribute Details

#__parentObject

Returns the value of attribute __parent.



6
7
8
# File 'lib/subelements.rb', line 6

def __parent
  @__parent
end

Instance Method Details

#create_xml(parent) ⇒ Object

Creates the XML for the element by using add_text on the value.



19
20
21
# File 'lib/subelements.rb', line 19

def create_xml(parent)
  parent << Nokogiri::XML::Text.new(@value, parent)
end

#elnameObject



40
41
42
# File 'lib/subelements.rb', line 40

def elname
  '__TEXT__'
end

#end_partial_export(file) ⇒ Object



28
29
# File 'lib/subelements.rb', line 28

def end_partial_export(file)
end

#partial_export(file) ⇒ Object



35
36
37
38
# File 'lib/subelements.rb', line 35

def partial_export(file)
  start_partial_export(file)
  end_partial_export(file)
end

#start_partial_export(file) ⇒ Object



31
32
33
# File 'lib/subelements.rb', line 31

def start_partial_export(file)
  file << self.xml_text
end

#to_sObject

Simple to_s method that just returns the included string



14
15
16
# File 'lib/subelements.rb', line 14

def to_s
  @value
end

#xml_textObject

The XML text of the element is simply it’s string value.



24
25
26
# File 'lib/subelements.rb', line 24

def xml_text
  @value
end