Class: Shale::Adapter::Nokogiri::Document Private
- Inherits:
-
Object
- Object
- Shale::Adapter::Nokogiri::Document
- Defined in:
- lib/shale/adapter/nokogiri/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 Nokogiri API
Instance Method Summary collapse
-
#add_attribute(element, name, value) ⇒ Object
private
Add attribute to Nokogiri element.
-
#add_element(element, child) ⇒ Object
private
Add child element to Nokogiri element.
-
#add_namespace(prefix, namespace) ⇒ Object
private
Add XML namespace to document.
-
#add_text(element, text) ⇒ Object
private
Add text node to Nokogiri element.
-
#create_cdata(text, parent) ⇒ Object
private
Create CDATA node and add it to parent.
-
#create_element(name) ⇒ ::Nokogiri::XML::Element
private
Create Nokogiri element.
-
#doc ⇒ ::Nokogiri::XML::Document
private
Return Nokogiri document.
-
#initialize(version = nil) ⇒ Document
constructor
private
Initialize object.
Constructor Details
#initialize(version = nil) ⇒ 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
15 16 17 18 19 20 21 |
# File 'lib/shale/adapter/nokogiri/document.rb', line 15 def initialize(version = nil) ver = nil ver = version if version.is_a?(String) @doc = ::Nokogiri::XML::Document.new(ver) @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 Nokogiri element
76 77 78 |
# File 'lib/shale/adapter/nokogiri/document.rb', line 76 def add_attribute(element, name, value) element[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 Nokogiri element
86 87 88 |
# File 'lib/shale/adapter/nokogiri/document.rb', line 86 def add_element(element, child) element.add_child(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
65 66 67 |
# File 'lib/shale/adapter/nokogiri/document.rb', line 65 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 Nokogiri element
96 97 98 |
# File 'lib/shale/adapter/nokogiri/document.rb', line 96 def add_text(element, text) element.content = 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
55 56 57 |
# File 'lib/shale/adapter/nokogiri/document.rb', line 55 def create_cdata(text, parent) parent.add_child(::Nokogiri::XML::CDATA.new(@doc, text)) end |
#create_element(name) ⇒ ::Nokogiri::XML::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 Nokogiri element
45 46 47 |
# File 'lib/shale/adapter/nokogiri/document.rb', line 45 def create_element(name) ::Nokogiri::XML::Element.new(name, @doc) end |
#doc ⇒ ::Nokogiri::XML::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 Nokogiri document
28 29 30 31 32 33 34 35 36 |
# File 'lib/shale/adapter/nokogiri/document.rb', line 28 def doc if @doc.root @namespaces.each do |prefix, namespace| @doc.root.add_namespace(prefix, namespace) end end @doc end |