Class: TaskJuggler::LogicalAttribute

Inherits:
LogicalOperation show all
Defined in:
lib/taskjuggler/LogicalOperation.rb

Overview

This class handles operands that are property attributes. They are addressed by attribute ID and scenario index. The expression provides the property reference.

Instance Attribute Summary

Attributes inherited from LogicalOperation

#operand1, #operand2, #operator

Instance Method Summary collapse

Constructor Details

#initialize(attribute, scenario) ⇒ LogicalAttribute

Returns a new instance of LogicalAttribute.



186
187
188
189
# File 'lib/taskjuggler/LogicalOperation.rb', line 186

def initialize(attribute, scenario)
  @scenario = scenario
  super
end

Instance Method Details

#eval(expr) ⇒ Object

To evaluate a property attribute we use the Query mechanism to retrieve the value.



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/taskjuggler/LogicalOperation.rb', line 193

def eval(expr)
  query = expr.query.dup
  query.scenarioIdx = @scenario.sequenceNo - 1
  query.attributeId = @operand1
  query.process
  if query.ok
    # The logical expressions are mostly about comparing values. So we use
    # the sortableResult of the Query. This creates some challenges for load
    # values, as the user is not accustomed to the internal representation
    # of those.
    # Convert nil results into empty Strings if necessary
    query.result || ''
  else
    expr.error(query.errorMessage)
    query.errorMessage
  end
end

#to_s(query) ⇒ Object

Dumps the LogicalOperation as String. If query is nil, the variable names are shown, otherwise their values.



213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/taskjuggler/LogicalOperation.rb', line 213

def to_s(query)
  if query
    query = query.dup
    query.scenarioIdx = @scenario.sequenceNo - 1
    query.attributeId = @operand1
    query.process
    unless query.ok
      return "Error in conversion to String: #{query.errorMessage}"
    end
    query.to_s
  else
    "#{@scenario.fullId}.#{@operand1}"
  end
end