Sha256: 8b05b8d2ab04a1d8fbd37266641ce9d40cabddef8515aa85f27c7fdafdd4ef08

Contents?: true

Size: 878 Bytes

Versions: 3

Compression:

Stored size: 878 Bytes

Contents

# frozen_string_literal: true

module Danica
  class Function::Name
    include Common
    attr_reader :name, :containers

    def initialize(name:, variables:)
      @name = name || :f
      @containers = variables.map { |v| wrap_value(v) }
    end

    def to(*args)
      "#{name}(#{description_variables(*args)})"
    end

    def variables
      containers.map(&:content)
    end

    private

    def description_variables(format, **options)
      variables_for(format).map do |value|
        value.to(format, options)
      end.join(', ')
    end

    def variables_for(format)
      case format.to_sym
      when :tex
        non_constant_variables
      when :gnu
        non_valued_variables
      end
    end

    def non_valued_variables
      variables.reject(&:valued?)
    end

    def non_constant_variables
      variables.reject(&:constant?)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
danica-2.7.7 lib/danica/function/name.rb
danica-2.7.6 lib/danica/function/name.rb
danica-2.7.5 lib/danica/function/name.rb