Sha256: c95d0a54dd08e222308c5092c5eb9beaa464f4a0b3f1506edc60fcd462a56271

Contents?: true

Size: 1.86 KB

Versions: 4

Compression:

Stored size: 1.86 KB

Contents

# frozen_string_literal: true

require_relative "unary_function"

module Plurimath
  module Math
    module Function
      class Tilde < UnaryFunction
        attr_accessor :attributes

        def initialize(parameter_one = nil, attributes = {})
          super(parameter_one)
          @attributes = attributes
        end

        def to_mathml_without_math_tag(intent)
          mover = ox_element("mover")
          mover[:accent] = attributes[:accent] if attributes&.dig(:accent)
          second_value = parameter_one.to_mathml_without_math_tag(intent) if parameter_one
          Utility.update_nodes(mover, [second_value, ox_element("mo") << "~"])
        end

        def to_omml_without_math_tag(display_style)
          return r_element("~", rpr_tag: false) unless parameter_one

          if attributes && attributes[:accent]
            acc_tag(display_style)
          else
            symbol = Symbols::Symbol.new("~")
            Overset.new(parameter_one, symbol).to_omml_without_math_tag(true)
          end
        end

        def validate_function_formula
          false
        end

        def to_unicodemath
          "#{unicodemath_parens(parameter_one)}̃"
        end

        def line_breaking(obj)
          parameter_one&.line_breaking(obj)
          obj.update(Utility.filter_values(obj.value)) if obj.value_exist?
        end

        protected

        def acc_tag(display_style)
          acc_tag    = Utility.ox_element("acc", namespace: "m")
          acc_pr_tag = Utility.ox_element("accPr", namespace: "m")
          acc_pr_tag << (Utility.ox_element("chr", namespace: "m", attributes: { "m:val": "˜" }))
          Utility.update_nodes(
            acc_tag,
            [
              acc_pr_tag,
              omml_parameter(parameter_one, display_style, tag_name: "e"),
            ],
          )
          [acc_tag]
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
plurimath-0.8.14 lib/plurimath/math/function/tilde.rb
plurimath-0.8.13 lib/plurimath/math/function/tilde.rb
plurimath-0.8.12 lib/plurimath/math/function/tilde.rb
plurimath-0.8.11 lib/plurimath/math/function/tilde.rb