lib/axiom/function.rb

Summary

Maintainability
A
0 mins
Test Coverage
# encoding: utf-8

module Axiom

  # Abstract base class for logical functions
  class Function
    include AbstractType, Adamantium, Visitable

    abstract_singleton_method :call, :type
    abstract_method :rename

    # Rename the attribute(s) inside the function
    #
    # @param [Function] operand
    #
    # @param [Algebra::Rename::Aliases] aliases
    #
    # @return [Function]
    #
    # @todo simplify once Attribute#rename works the same as Function#rename
    #
    # @api private
    def self.rename_attributes(operand, aliases)
      if operand.respond_to?(:rename) && !operand.kind_of?(Attribute)
        operand.rename(aliases)
      else
        aliases[operand]
      end
    end

    # Extract the value from the operand or tuple
    #
    # @param [Object, #call] operand
    #   the operand to extract the value from
    # @param [Tuple] tuple
    #   the tuple to pass in to the operand if it responds to #call
    #
    # @return [Object]
    #
    # @api private
    def self.extract_value(operand, tuple)
      operand.respond_to?(:call) ? operand.call(tuple) : operand
    end

    # Return the function type
    #
    # @example
    #   type = function.type  # => Axiom::Types::Object
    #
    # @return [Class<Types::Object>]
    #
    # @api public
    def type
      self.class.type
    end

  end # class Function
end # module Axiom