Class: TaskJuggler::LogicalFunction
- 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
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#name ⇒ Object
Returns the value of attribute name.
Instance Method Summary collapse
-
#eval(expr) ⇒ Object
Evaluate the function by calling it with the arguments.
-
#initialize(opnd) ⇒ LogicalFunction
constructor
Create a new LogicalFunction.
-
#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.
-
#to_s ⇒ Object
Return a textual expression of the function call.
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
#arguments ⇒ Object
Returns the value of attribute arguments.
22 23 24 |
# File 'lib/taskjuggler/LogicalFunction.rb', line 22 def arguments @arguments end |
#name ⇒ Object
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_s ⇒ Object
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 |