Sha256: da7a3e9e4d0b1afe9355120d6b7289b19c755d57b417e93d0e35adaa38a2ebe8

Contents?: true

Size: 708 Bytes

Versions: 3

Compression:

Stored size: 708 Bytes

Contents

# frozen_string_literal: true

module Danica
  class Operator::Functional < Operator
    variables :value
    default_value :is_grouped?, true

    def self.build(operator:, text: nil, tex: nil, gnu: nil)
      text = "#{operator}(:value:)" if text.nil?
      tex = text if tex.nil?
      gnu = text if gnu.nil?

      Class.new(self) do
        module_eval(%(
          def to_f
            Math.#{operator}(value.to_f)
          end

          def to_tex(**options)
            '#{tex.gsub(':value:', "' + value.to_tex(options) + '")}'
          end

          def to_gnu(**options)
            '#{gnu.gsub(':value:', "' + value.to_gnu(options) + '")}'
          end
        ))
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
danica-2.7.7 lib/danica/operator/functional.rb
danica-2.7.6 lib/danica/operator/functional.rb
danica-2.7.5 lib/danica/operator/functional.rb