Class: Shale::Adapter::REXML::Document Private
- Inherits:
-
Object
- Object
- Shale::Adapter::REXML::Document
- Defined in:
- lib/shale/adapter/rexml/document.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Wrapper around REXML API
Instance Method Summary collapse
-
#add_attribute(element, name, value) ⇒ Object
private
Add attribute to REXML element.
-
#add_element(element, child) ⇒ Object
private
Add child element to REXML element.
-
#add_namespace(prefix, namespace) ⇒ Object
private
Add XML namespace to document.
-
#add_text(element, text) ⇒ Object
private
Add text node to REXML element.
-
#create_cdata(text, parent) ⇒ Object
private
Create CDATA node and add it to parent.
-
#create_element(name) ⇒ ::REXML::Element
private
Create REXML element.
-
#doc ⇒ ::REXML::Document
private
Return REXML document.
-
#initialize ⇒ Document
constructor
private
Initialize object.
Constructor Details
#initialize ⇒ Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize object
13 14 15 16 17 |
# File 'lib/shale/adapter/rexml/document.rb', line 13 def initialize context = { attribute_quote: :quote, prologue_quote: :quote } @doc = ::REXML::Document.new(nil, context) @namespaces = {} end |
Instance Method Details
#add_attribute(element, name, value) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add attribute to REXML element
72 73 74 |
# File 'lib/shale/adapter/rexml/document.rb', line 72 def add_attribute(element, name, value) element.add_attribute(name, value || '') end |
#add_element(element, child) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add child element to REXML element
82 83 84 |
# File 'lib/shale/adapter/rexml/document.rb', line 82 def add_element(element, child) element.add_element(child) end |
#add_namespace(prefix, namespace) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add XML namespace to document
61 62 63 |
# File 'lib/shale/adapter/rexml/document.rb', line 61 def add_namespace(prefix, namespace) @namespaces[prefix] = namespace if prefix && namespace end |
#add_text(element, text) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Add text node to REXML element
92 93 94 |
# File 'lib/shale/adapter/rexml/document.rb', line 92 def add_text(element, text) element.add_text(text) end |
#create_cdata(text, parent) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create CDATA node and add it to parent
51 52 53 |
# File 'lib/shale/adapter/rexml/document.rb', line 51 def create_cdata(text, parent) ::REXML::CData.new(text, true, parent) end |
#create_element(name) ⇒ ::REXML::Element
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create REXML element
41 42 43 |
# File 'lib/shale/adapter/rexml/document.rb', line 41 def create_element(name) ::REXML::Element.new(name, nil, attribute_quote: :quote) end |
#doc ⇒ ::REXML::Document
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Return REXML document
24 25 26 27 28 29 30 31 32 |
# File 'lib/shale/adapter/rexml/document.rb', line 24 def doc if @doc.root @namespaces.each do |prefix, namespace| @doc.root.add_namespace(prefix, namespace) end end @doc end |