Class: Plurimath::XmlEngine::Oga
- Inherits:
-
Object
- Object
- Plurimath::XmlEngine::Oga
show all
- Defined in:
- lib/plurimath/xml_engine/oga.rb,
lib/plurimath/xml_engine/oga/node.rb,
lib/plurimath/xml_engine/oga/dumper.rb,
lib/plurimath/xml_engine/oga/element.rb,
lib/plurimath/xml_engine/oga/wrapper.rb,
lib/plurimath/xml_engine/oga/document.rb
Defined Under Namespace
Classes: Document, Dumper, Element, Node, Wrapper
Class Method Summary
collapse
Class Method Details
.dump(data, indent: nil) ⇒ Object
15
16
17
|
# File 'lib/plurimath/xml_engine/oga.rb', line 15
def dump(data, indent: nil)
Dumper.new(data, indent: indent).dump.out
end
|
26
27
28
29
|
# File 'lib/plurimath/xml_engine/oga.rb', line 26
def (node)
node = node.unwrap if node.respond_to? :unwrap
node.is_a?(::Oga::XML::Comment)
end
|
.load(data) ⇒ Object
19
20
21
22
23
24
|
# File 'lib/plurimath/xml_engine/oga.rb', line 19
def load(data)
data = ::Oga::XML::Parser.new(data, html: true).parse
return Document.new(data) if data.xml_declaration
Document.new(data).nodes.first
end
|
.new_element(name) ⇒ Object
10
11
12
13
|
# File 'lib/plurimath/xml_engine/oga.rb', line 10
def new_element(name)
data = ::Oga::XML::Element.new(name: name)
Node.new(data)
end
|
.replace_nodes(root, nodes) ⇒ Object
31
32
33
34
35
|
# File 'lib/plurimath/xml_engine/oga.rb', line 31
def replace_nodes(root, nodes)
text_node = ::Oga::XML::Text.new(text: nodes)
root.unwrap.children = ::Oga::XML::NodeSet.new([text_node])
root
end
|