Class: Plurimath::XmlEngine::Oga

Inherits:
Object
  • Object
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



21
22
23
# File 'lib/plurimath/xml_engine/oga.rb', line 21

def dump(data, indent: nil)
  Dumper.new(data, indent: indent).dump.out
end

.is_xml_comment?(node) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
# File 'lib/plurimath/xml_engine/oga.rb', line 32

def is_xml_comment?(node)
  node = node.unwrap if node.respond_to? :unwrap
  node.is_a?(::Oga::XML::Comment)
end

.load(data) ⇒ Object



25
26
27
28
29
30
# File 'lib/plurimath/xml_engine/oga.rb', line 25

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



16
17
18
19
# File 'lib/plurimath/xml_engine/oga.rb', line 16

def new_element(name)
  data = ::Oga::XML::Element.new(name: name)
  Node.new(data)
end

.replace_nodes(root, nodes) ⇒ Object



37
38
39
40
41
# File 'lib/plurimath/xml_engine/oga.rb', line 37

def replace_nodes(root, nodes)
  text_node = ::Oga::XML::Text.new(text: nodes)
  root.unwrap.children = ::Oga::XML::NodeSet.new([text_node])
  root
end