Class: TaskJuggler::LogicalFunction

Inherits:
Object
  • Object
show all
Defined in:
lib/taskjuggler/LogicalFunction.rb

Overview

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

Constant Summary collapse

@@functions =

A map with the names of the supported functions and the number of arguments they require.

{
    'hasalert' => 1,
    'isactive' => 1,
    'ischildof' => 1,
    'isdependencyof' => 3,
    'isdutyof' => 2,
    'isfeatureof' => 2,
    'isleaf' => 0,
    'ismilestone' => 1,
    'isongoing' => 1,
    'isresource' => 0,
    'isresponsibilityof' => 2,
    'istask' => 0,
    'isvalid' => 1,
    'treelevel' => 0
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opnd) ⇒ LogicalFunction

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



44
45
46
47
48
49
50
51
52
53
54
55
56
# 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

Instance Attribute Details

#argumentsObject

Returns the value of attribute arguments.



22
23
24
# File 'lib/taskjuggler/LogicalFunction.rb', line 22

def arguments
  @arguments
end

#nameObject

Returns the value of attribute name.



22
23
24
# File 'lib/taskjuggler/LogicalFunction.rb', line 22

def name
  @name
end

Instance Method Details

#eval(expr) ⇒ Object

Evaluate the function by calling it with the arguments.



76
77
78
79
# File 'lib/taskjuggler/LogicalFunction.rb', line 76

def eval(expr)
  # Call the function and return the result.
  send(name, expr, @arguments)
end

#setArgumentsAndCheck(args) ⇒ Object

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.



61
62
63
64
65
66
67
68
69
70
71
72
73
# 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_sObject

Return a textual expression of the function call.



82
83
84
# File 'lib/taskjuggler/LogicalFunction.rb', line 82

def to_s
  "#{@name}(#{@arguments.join(', ')})"
end