Class TaskJuggler::LogicalFunction
In: lib/taskjuggler/LogicalFunction.rb
Parent: Object

The LogicalFunction is a specialization of the LogicalOperation. It models a function call in a LogicalExpression.

Methods

eval   new   setArgumentsAndCheck   to_s  

Attributes

arguments  [RW] 
name  [RW] 

Public Class methods

Create a new LogicalFunction. opnd is the name of the function.

[Source]

# File lib/taskjuggler/LogicalFunction.rb, line 43
    def initialize(opnd)
      if opnd[-1] == ?_
        # Function names with a trailing _ are like their counterparts without
        # the _. But during evaluation the property and the scope properties
        # will be switched.
        @name = opnd[0..-2]
        @invertProperties = true
      else
        @name = opnd
        @invertProperties = false
      end
      @arguments = []
    end

Public Instance methods

Evaluate the function by calling it with the arguments.

[Source]

# File lib/taskjuggler/LogicalFunction.rb, line 75
    def eval(expr)
      # Call the function and return the result.
      send(name, expr, @arguments)
    end

Register the arguments of the function and check if the name is a known function and the number of arguments match this function. If not, return an [ id, message ] error. Otherwise nil.

[Source]

# File lib/taskjuggler/LogicalFunction.rb, line 60
    def setArgumentsAndCheck(args)
      unless @@functions.include?(@name)
        return [ 'unknown_function',
                 "Unknown function #{@name} used in logical expression." ]
      end
      if @@functions[@name] != args.length
        return [ 'wrong_no_func_arguments',
                 "Wrong number of arguments for function #{@name}. Got " +
                 "#{args.length} instead of #{@@functions[@name]}." ]
      end
      @arguments = args
      nil
    end

Return a textual expression of the function call.

[Source]

# File lib/taskjuggler/LogicalFunction.rb, line 81
    def to_s
      "#{@name}(#{@arguments.join(', ')})"
    end

[Validate]