Class: Plurimath::XMLEngine::Oga

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/xml_engine/oga.rb

Defined Under Namespace

Classes: Document, Dumper, Node, Wrapper

Constant Summary collapse

Comment =
::Oga::XML::Comment

Class Method Summary collapse

Class Method Details

.dump(data, indent: nil) ⇒ Object



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

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

.is_xml_comment?(node) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/plurimath/xml_engine/oga.rb', line 29

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

.load(data) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/plurimath/xml_engine/oga.rb', line 20

def load(data)
  data = ::Oga::XML::Parser.new(data, html: true).parse
  if data.xml_declaration
    Document.new(data)
  else
    Document.new(data).nodes.first
  end
end

.new_element(name) ⇒ Object



11
12
13
14
# File 'lib/plurimath/xml_engine/oga.rb', line 11

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

.replace_nodes(root, nodes) ⇒ Object



34
35
36
37
# File 'lib/plurimath/xml_engine/oga.rb', line 34

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