Sha256: 49d84137cf969e7241b614e9507021fb3c09641904a7083b593cca6aa3ade7f7

Contents?: true

Size: 847 Bytes

Versions: 4

Compression:

Stored size: 847 Bytes

Contents

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

4 entries across 4 versions & 1 rubygems

Version Path
danica-2.7.4 lib/danica/function/name.rb
danica-2.7.3 lib/danica/function/name.rb
danica-2.7.2 lib/danica/function/name.rb
danica-2.7.1 lib/danica/function/name.rb