Class: Sts::IsoSts::Mathml2::Math

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/sts/iso_sts/mathml2/math.rb

Constant Summary collapse

MATH_XPATH =
".//*[local-name()='math']"
MATH_NS_XPATH =
".//math[@xmlns='http://www.w3.org/1998/Math/MathML']"
MATH_ML_XPATH =
".//mml:math"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_xml(input) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sts/iso_sts/mathml2/math.rb', line 35

def self.from_xml(input)
  doc = Nokogiri::XML(input, &:strict)
  math_element = find_math_element(doc)
  return new if math_element.nil?

  math = new
  math.id = math_element["id"]
  math.display = math_element["display"]
  math.content = extract_inner_content(math_element)
  math.instance_variable_set(:@original_xml, math_element.to_xml)
  math
end

Instance Method Details

#to_xmlObject



21
22
23
24
25
26
27
28
29
# File 'lib/sts/iso_sts/mathml2/math.rb', line 21

def to_xml(*)
  if content
    Nokogiri::XML(content, &:strict).root.to_xml
  elsif @original_xml
    @original_xml
  else
    %{<math xmlns="#{::Sts::Namespaces::MathmlNamespace.uri}"/>}
  end
end