Sha256: ca2a8ac15874a662f09ba90a191863831a730b7e80478cc4c2a8e145177d3916

Contents?: true

Size: 1.96 KB

Versions: 3

Compression:

Stored size: 1.96 KB

Contents

# frozen_string_literal: true

require_relative "unary_function"

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

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

        def to_mathml_without_math_tag
          dot_tag = (Utility.ox_element("mo") << ".")
          return dot_tag unless parameter_one

          first_value = parameter_one&.to_mathml_without_math_tag
          dot_tag = (Utility.ox_element("mo") << ".")
          over_tag = Utility.ox_element("mover")
          over_tag.attributes.merge!({ accent: attributes[:accent] }) if attributes && attributes[:accent]
          Utility.update_nodes(
            over_tag,
            [
              first_value,
              dot_tag,
            ],
          )
        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 = Symbol.new(".")
            Overset.new(parameter_one, symbol).to_omml_without_math_tag(true)
          end
        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

3 entries across 3 versions & 1 rubygems

Version Path
plurimath-0.7.2 lib/plurimath/math/function/dot.rb
plurimath-0.7.1 lib/plurimath/math/function/dot.rb
plurimath-0.7.0 lib/plurimath/math/function/dot.rb