Parent

Files

Class Index [+]

Quicksearch

TaskJuggler::LogicalFunction

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

Attributes

name[RW]
arguments[RW]

Public Class Methods

new(opnd) click to toggle source

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

    # File lib/LogicalFunction.rb, line 38
38:     def initialize(opnd)
39:       if opnd[1] == __
40:         # Function names with a trailing _ are like their counterparts without
41:         # the _. But during evaluation the property and the scope properties
42:         # will be switched.
43:         @name = opnd[0..2]
44:         @invertProperties = true
45:       else
46:         @name = opnd
47:         @invertProperties = false
48:       end
49:       @arguments = []
50:     end

Public Instance Methods

eval(expr) click to toggle source

Evaluate the function by calling it with the arguments.

    # File lib/LogicalFunction.rb, line 70
70:     def eval(expr)
71:       args = []
72:       # Call the function and return the result.
73:       send(name, expr, @arguments)
74:     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/LogicalFunction.rb, line 55
55:     def setArgumentsAndCheck(args)
56:       unless @@functions.include?(@name)
57:         return [ 'unknown_function',
58:                  "Unknown function #{@name} used in logical expression." ]
59:       end
60:       if @@functions[@name] != args.length
61:         return [ 'wrong_no_func_arguments',
62:                  "Wrong number of arguments for function #{@name}. Got " +
63:                  "#{args.length} instead of #{@@functions[@name]}." ]
64:       end
65:       @arguments = args
66:       nil
67:     end
to_s() click to toggle source

Return a textual expression of the function call.

    # File lib/LogicalFunction.rb, line 77
77:     def to_s
78:       "#{@name}(#{@arguments.join(', ')})"
79:     end

Private Instance Methods

hasalert(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 93
 93:     def hasalert(expr, args)
 94:       property, scopeProperty = properties(expr)
 95:       query = expr.query
 96:       project = property.project
 97:       date = project.reportContext.report.get('end')
 98:       !project['journal'].currentEntries(query.end, property,
 99:                                          args[0], query.start).empty?
100:     end
isactive(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 102
102:     def isactive(expr, args)
103:       property, scopeProperty = properties(expr)
104:       # The result can only be true when called for a Task property.
105:       return false unless property.is_a?(Task) ||
106:                           property.is_a?(Resource)
107:       project = property.project
108:       # 1st arg must be a scenario index.
109:       if (scenarioIdx = project.scenarioIdx(args[0])).nil?
110:         expr.error("Unknown scenario '#{args[0]}' used for function isactive()")
111:       end
112: 
113:       property.getAllocatedTime(scenarioIdx,
114:                                 project.reportContext.report.get('start'),
115:                                 project.reportContext.report.get('end'),
116:                                 scopeProperty) > 0.0
117:     end
isdependencyof(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 119
119:     def isdependencyof(expr, args)
120:       property, scopeProperty = properties(expr)
121:       # The result can only be true when called for a Task property.
122:       return false unless property.is_a?(Task)
123:       project = property.project
124:       # 1st arg must be a task ID.
125:       return false if (task = project.task(args[0])).nil?
126:       # 2nd arg must be a scenario index.
127:       return false if (scenarioIdx = project.scenarioIdx(args[1])).nil?
128:       # 3rd arg must be an integer number.
129:       return false unless args[2].is_a?(Fixnum)
130: 
131:       property.isDependencyOf(scenarioIdx, task, args[2])
132:     end
isdutyof(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 134
134:     def isdutyof(expr, args)
135:       property, scopeProperty = properties(expr)
136:       # The result can only be true when called for a Task property.
137:       return false unless (task = property).is_a?(Task)
138:       project = task.project
139:       # 1st arg must be a resource ID.
140:       return false if (resource = project.resource(args[0])).nil?
141:       # 2nd arg must be a scenario index.
142:       return false if (scenarioIdx = project.scenarioIdx(args[1])).nil?
143: 
144:       task['assignedresources', scenarioIdx].include?(resource)
145:     end
isleaf(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 147
147:     def isleaf(expr, args)
148:       property, scopeProperty = properties(expr)
149:       return false unless property
150:       property.leaf?
151:     end
isongoing(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 153
153:     def isongoing(expr, args)
154:       property, scopeProperty = properties(expr)
155:       # The result can only be true when called for a Task property.
156:       return false unless (task = property).is_a?(Task)
157:       project = task.project
158:       # 1st arg must be a scenario index.
159:       if (scenarioIdx = project.scenarioIdx(args[0])).nil?
160:         expr.error("Unknown scenario '#{args[0]}' used for function isongoing()")
161:       end
162: 
163:       iv1 = Interval.new(project.reportContext.report.get('start'),
164:                          project.reportContext.report.get('end'))
165:       tStart = task['start', scenarioIdx]
166:       tEnd = task['end', scenarioIdx]
167:       # This helps to show tasks with scheduling errors.
168:       return true unless tStart && tEnd
169:       iv2 = Interval.new(tStart, tEnd)
170: 
171:       return iv1.overlaps?(iv2)
172:     end
isresource(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 174
174:     def isresource(expr, args)
175:       property, scopeProperty = properties(expr)
176:       property.is_a?(Resource)
177:     end
istask(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 179
179:     def istask(expr, args)
180:       property, scopeProperty = properties(expr)
181:       property.is_a?(Task)
182:     end
properties(expr) click to toggle source

Return the property and scope property as determined by the @invertProperties setting.

    # File lib/LogicalFunction.rb, line 85
85:     def properties(expr)
86:       if @invertProperties
87:         return expr.query.scopeProperty, nil
88:       else
89:         return expr.query.property, expr.query.scopeProperty
90:       end
91:     end
treelevel(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 184
184:     def treelevel(expr, args)
185:       property, scopeProperty = properties(expr)
186:       property.level + 1
187:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.