Class: TaskJuggler::LogicalExpression
- Defined in:
- lib/taskjuggler/LogicalExpression.rb
Overview
A LogicalExpression is an object that describes tree of LogicalOperation objects and the context that it should be evaluated in.
Instance Attribute Summary collapse
-
#query ⇒ Object
readonly
Returns the value of attribute query.
-
#sourceFileInfo ⇒ Object
readonly
Returns the value of attribute sourceFileInfo.
Instance Method Summary collapse
-
#error(text) ⇒ Object
This is an internal function.
-
#eval(query) ⇒ Object
This function triggers the evaluation of the expression.
-
#initialize(op, sourceFileInfo = nil) ⇒ LogicalExpression
constructor
Create a new LogicalExpression object.
-
#to_s(query = nil) ⇒ Object
Dump the LogicalExpression as a String.
Constructor Details
#initialize(op, sourceFileInfo = nil) ⇒ LogicalExpression
Create a new LogicalExpression object. op must be a LogicalOperation. sourceFileInfo is the file position where expression started. It may be nil if not available.
30 31 32 33 34 35 |
# File 'lib/taskjuggler/LogicalExpression.rb', line 30 def initialize(op, sourceFileInfo = nil) @operation = op @sourceFileInfo = sourceFileInfo @query = nil end |
Instance Attribute Details
#query ⇒ Object (readonly)
Returns the value of attribute query.
25 26 27 |
# File 'lib/taskjuggler/LogicalExpression.rb', line 25 def query @query end |
#sourceFileInfo ⇒ Object (readonly)
Returns the value of attribute sourceFileInfo.
25 26 27 |
# File 'lib/taskjuggler/LogicalExpression.rb', line 25 def sourceFileInfo @sourceFileInfo end |
Instance Method Details
#error(text) ⇒ Object
This is an internal function. It’s called by the LogicalOperation methods in case something went wrong during an evaluation.
61 62 63 |
# File 'lib/taskjuggler/LogicalExpression.rb', line 61 def error(text) # :nodoc: raise TjException.new, "#{to_s}\nLogical expression error: #{text}" end |
#eval(query) ⇒ Object
This function triggers the evaluation of the expression. property is the PropertyTreeNode that should be used for the evaluation. scopeProperty is the PropertyTreeNode that describes the scope. It may be nil.
40 41 42 43 44 45 46 47 |
# File 'lib/taskjuggler/LogicalExpression.rb', line 40 def eval(query) @query = query res = @operation.eval(self) return res if res.is_a?(TrueClass) || res.is_a?(FalseClass) || res.is_a?(String) # In TJP syntax 'non 0' means false. return res != 0 end |
#to_s(query = nil) ⇒ Object
Dump the LogicalExpression as a String. If query is provided, it will show the actual values, otherwise just the variable names.
51 52 53 54 55 56 57 |
# File 'lib/taskjuggler/LogicalExpression.rb', line 51 def to_s(query = nil) if @sourceFileInfo.nil? "#{@operation.to_s(query)}" else "#{@sourceFileInfo} #{@operation.to_s(query)}" end end |