Module: Plurimath::Formatter::Numbers::MathmlRenderer
- Defined in:
- lib/plurimath/formatter/numbers/mathml_renderer.rb
Overview
Renders a Formatter result (FormattedNotation, FormattedNumber, or String) into a MathML element tree. Number delegates to this so the model does not carry format-specific XML construction.
Class Method Summary collapse
- .plain_element(result) ⇒ Object
- .render(result) ⇒ Object
- .render_notation(notation) ⇒ Object
- .render_semantic_base(formatted) ⇒ Object
Class Method Details
.plain_element(result) ⇒ Object
50 51 52 |
# File 'lib/plurimath/formatter/numbers/mathml_renderer.rb', line 50 def plain_element(result) Utility.ox_element("mn") << result.to_s end |
.render(result) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/plurimath/formatter/numbers/mathml_renderer.rb', line 12 def render(result) case result when FormattedNotation then render_notation(result) when FormattedNumber result.base_notation.semantic? ? render_semantic_base(result) : plain_element(result) else plain_element(result) end end |
.render_notation(notation) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/plurimath/formatter/numbers/mathml_renderer.rb', line 22 def render_notation(notation) return plain_element(notation) if notation.notation_style == :e coeff = plain_element(notation.coefficient) times = Utility.ox_element("mo") << notation.times_symbol.to_s base_el = Utility.ox_element("mn") << "10" exp_el = Utility.ox_element("mn") << notation.formatted_exponent sup = Utility.ox_element("msup") Utility.update_nodes(sup, [base_el, exp_el]) row = Utility.ox_element("mrow") Utility.update_nodes(row, [coeff, times, sup]) row end |
.render_semantic_base(formatted) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/plurimath/formatter/numbers/mathml_renderer.rb', line 36 def render_semantic_base(formatted) digits = Utility.ox_element("mn") << formatted.digits_string base_el = Utility.ox_element("mn") << formatted.base_notation.base.to_s sub = Utility.ox_element("msub") Utility.update_nodes(sub, [digits, base_el]) return sub unless formatted.sign_text sign_el = Utility.ox_element("mo") << formatted.sign_text row = Utility.ox_element("mrow") Utility.update_nodes(row, [sign_el, sub]) row end |