Parent

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 39
39:     def initialize(opnd)
40:       if opnd[1] == __
41:         # Function names with a trailing _ are like their counterparts without
42:         # the _. But during evaluation the property and the scope properties
43:         # will be switched.
44:         @name = opnd[0..2]
45:         @invertProperties = true
46:       else
47:         @name = opnd
48:         @invertProperties = false
49:       end
50:       @arguments = []
51:     end

Public Instance Methods

eval(expr) click to toggle source

Evaluate the function by calling it with the arguments.

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

Return a textual expression of the function call.

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

Private Instance Methods

hasalert(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 94
 94:     def hasalert(expr, args)
 95:       property, scopeProperty = properties(expr)
 96:       query = expr.query
 97:       project = property.project
 98:       date = project.reportContexts.last.report.get('end')
 99:       !project['journal'].currentEntries(query.end, property,
100:                                          args[0], query.start).empty?
101:     end
isactive(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 103
103:     def isactive(expr, args)
104:       property, scopeProperty = properties(expr)
105:       # The result can only be true when called for a Task property.
106:       return false unless property.is_a?(Task) ||
107:                           property.is_a?(Resource)
108:       project = property.project
109:       # 1st arg must be a scenario index.
110:       if (scenarioIdx = project.scenarioIdx(args[0])).nil?
111:         expr.error("Unknown scenario '#{args[0]}' used for function isactive()")
112:       end
113: 
114:       query = expr.query
115:       property.getAllocatedTime(scenarioIdx, query.start, query.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
isfeatureof(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 147
147:     def isfeatureof(expr, args)
148:       property, scopeProperty = properties(expr)
149:       # The result can only be true when called for a Task property.
150:       return false unless property.is_a?(Task)
151:       project = property.project
152:       # 1st arg must be a task ID.
153:       return false if (task = project.task(args[0])).nil?
154:       # 2nd arg must be a scenario index.
155:       return false if (scenarioIdx = project.scenarioIdx(args[1])).nil?
156: 
157:       property.isFeatureOf(scenarioIdx, task)
158:     end
isleaf(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 160
160:     def isleaf(expr, args)
161:       property, scopeProperty = properties(expr)
162:       return false unless property
163:       property.leaf?
164:     end
isongoing(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 166
166:     def isongoing(expr, args)
167:       property, scopeProperty = properties(expr)
168:       # The result can only be true when called for a Task property.
169:       return false unless (task = property).is_a?(Task)
170:       project = task.project
171:       # 1st arg must be a scenario index.
172:       if (scenarioIdx = project.scenarioIdx(args[0])).nil?
173:         expr.error("Unknown scenario '#{args[0]}' used for function isongoing()")
174:       end
175: 
176:       query = expr.query
177:       iv1 = Interval.new(query.start, query.end)
178:       tStart = task['start', scenarioIdx]
179:       tEnd = task['end', scenarioIdx]
180:       # This helps to show tasks with scheduling errors.
181:       return true unless tStart && tEnd
182:       iv2 = Interval.new(tStart, tEnd)
183: 
184:       return iv1.overlaps?(iv2)
185:     end
isresource(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 187
187:     def isresource(expr, args)
188:       property, scopeProperty = properties(expr)
189:       property.is_a?(Resource)
190:     end
istask(expr, args) click to toggle source
     # File lib/LogicalFunction.rb, line 192
192:     def istask(expr, args)
193:       property, scopeProperty = properties(expr)
194:       property.is_a?(Task)
195:     end
properties(expr) click to toggle source

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

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

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.