Sha256: 3983b932e7c7be2e86593ee0659471c4fb8ce7c727f0ed05f071c61aef07dc9a

Contents?: true

Size: 838 Bytes

Versions: 1

Compression:

Stored size: 838 Bytes

Contents

# frozen_string_literal: true

module Plurimath
  module Math
    class Formula
      attr_accessor :value

      def initialize(value = [])
        @value = value.is_a?(Array) ? value : [value]
      end

      def ==(object)
        object.value == value
      end

      def to_asciimath
        value.map(&:to_asciimath).join
      end

      def to_mathml
        <<~MATHML
          <math xmlns='http://www.w3.org/1998/Math/MathML'>
            <mstyle displaystyle='true'>
              #{mathml_content}
            </mstyle>
          </math>
        MATHML
      end

      def to_mathml_without_math_tag
        "<mrow>#{mathml_content}</mrow>"
      end

      def mathml_content
        value.map(&:to_mathml_without_math_tag).join
      end

      def to_latex
        value.map(&:to_latex).join
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
plurimath-0.2.0 lib/plurimath/math/formula.rb