class TaskJuggler::LogicalFunction
The LogicalFunction
is a specialization of the LogicalOperation
. It models a function call in a LogicalExpression
.
Attributes
arguments[RW]
name[RW]
Public Class Methods
new(opnd)
click to toggle source
Create a new LogicalFunction
. opnd is the name of the function.
# File lib/taskjuggler/LogicalFunction.rb, line 44 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
eval(expr)
click to toggle source
Evaluate the function by calling it with the arguments.
# File lib/taskjuggler/LogicalFunction.rb, line 76 def eval(expr) # Call the function and return the result. send(name, expr, @arguments) end
setArgumentsAndCheck(args)
click to toggle source
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.
# File lib/taskjuggler/LogicalFunction.rb, line 61 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
to_s()
click to toggle source
Return a textual expression of the function call.
# File lib/taskjuggler/LogicalFunction.rb, line 82 def to_s "#{@name}(#{@arguments.join(', ')})" end