lib/LogicalExpression.rb in taskjuggler-0.0.3 vs lib/LogicalExpression.rb in taskjuggler-0.0.4

- old
+ new

@@ -1,11 +1,11 @@ #!/usr/bin/env ruby -w # encoding: UTF-8 # # = LogicalExpression.rb -- The TaskJuggler III Project Management Software # -# Copyright (c) 2006, 2007, 2008, 2009 by Chris Schlaeger <cs@kde.org> +# Copyright (c) 2006, 2007, 2008, 2009, 2010 by Chris Schlaeger <cs@kde.org> # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # @@ -19,30 +19,36 @@ # A LogicalExpression is an object that describes tree of LogicalOperation # objects and the context that it should be evaluated in. class LogicalExpression - attr_reader :property, :sourceFileInfo + attr_reader :query, :sourceFileInfo # 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. def initialize(op, sourceFileInfo = nil) @operation = op @sourceFileInfo = sourceFileInfo - @property = @scopeProperty = nil + @query = nil end + # Switch the scopeProperty to property. We need this for the scopeProperty + # operating functions. The @scopeProperty is set to nil. + def flipProperties + @query.property, @query.scopeProperty = @query.scopeProperty, nil + end + # 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. - def eval(property, scopeProperty) - @property = property - @scopeProperty = scopeProperty + def eval(query) + @query = query res = @operation.eval(self) - return res if res.class == TrueClass || res.class == FalseClass + return res if res.class == TrueClass || res.class == FalseClass || + res.class == String # In TJP syntax 'non 0' means false. return res != 0 end # This function is only used for debugging. @@ -55,15 +61,10 @@ end # This is an internal function. It's called by the LogicalOperation methods # in case something went wrong during an evaluation. def error(text) # :nodoc: - if @sourceFileInfo.nil? - str = "Logical expression error: " + text - else - str = "#{@sourceFileInfo} Logical expression error: #{text}\n" - end - raise TjException.new, str + raise TjException.new, "#{to_s}\nLogical expression error: #{text}" end end end