Class: ActiveFacts::CQL::Compiler::Comparison

Inherits:
Operation
  • Object
show all
Defined in:
lib/activefacts/cql/compiler/expression.rb

Instance Attribute Summary collapse

Attributes inherited from Operation

#binding, #certainty, #clause, #fact_type, #player, #role, #role_ref

Instance Method Summary collapse

Methods inherited from Operation

#identify_other_players, #identify_players_with_role_name, #is_existential_type, #is_naked_object_type, #leading_adjective, #literal, #match_existing_fact_type, #nested_clauses, #objectification_of, #objectified_as, #operands, #result_value_type, #role_name, #side_effects, #trailing_adjective, #value_constraint

Constructor Details

#initialize(operator, e1, e2, certainty = true) ⇒ Comparison

Returns a new instance of Comparison.



157
158
159
# File 'lib/activefacts/cql/compiler/expression.rb', line 157

def initialize operator, e1, e2, certainty = true
  @operator, @e1, @e2, @certainty, @qualifiers = operator, e1, e2, certainty, []
end

Instance Attribute Details

#conjunctionObject

Returns the value of attribute conjunction.



155
156
157
# File 'lib/activefacts/cql/compiler/expression.rb', line 155

def conjunction
  @conjunction
end

#e1Object

Returns the value of attribute e1.



155
156
157
# File 'lib/activefacts/cql/compiler/expression.rb', line 155

def e1
  @e1
end

#e2Object

Returns the value of attribute e2.



155
156
157
# File 'lib/activefacts/cql/compiler/expression.rb', line 155

def e2
  @e2
end

#operatorObject

Returns the value of attribute operator.



155
156
157
# File 'lib/activefacts/cql/compiler/expression.rb', line 155

def operator
  @operator
end

#qualifiersObject

Returns the value of attribute qualifiers.



155
156
157
# File 'lib/activefacts/cql/compiler/expression.rb', line 155

def qualifiers
  @qualifiers
end

Instance Method Details

#bind(context) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/activefacts/cql/compiler/expression.rb', line 165

def bind context
  refs.each do |o|
    o.bind context
  end

  # REVISIT: Return the projected binding instead:
  return @result = nil if @projection

  name = 'Boolean'
  @player = result_value_type(context, name)
  key = "#{name} #{object_id}"  # Every Comparison result is a unique Binding
  @binding = (context.bindings[key] ||= Binding.new(@player))
  @binding.refs << self
  @binding
end

#identify_player(context) ⇒ Object



189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/activefacts/cql/compiler/expression.rb', line 189

def identify_player context
  @player || begin
    if @projection
      raise "REVISIT: The player is the projected expression"
    end
    v = context.vocabulary
    @boolean ||=
	      v.constellation.ValueType[[[v.name], 'Boolean']] ||
	      v.constellation.ValueType(v, 'Boolean', :concept => :new)
    @player = @boolean
  end
end

#inspectObject

def project lr

  @projection = lr
  projected_rr = lr == :left ? @e2 : @e1
  true
end


210
# File 'lib/activefacts/cql/compiler/expression.rb', line 210

def inspect; to_s; end

#is_equality_comparisonObject



185
186
187
# File 'lib/activefacts/cql/compiler/expression.rb', line 185

def is_equality_comparison
  @operator == '='
end

#refsObject



161
162
163
# File 'lib/activefacts/cql/compiler/expression.rb', line 161

def refs
  [@e1, @e2]
end

#result_type_name(context) ⇒ Object



181
182
183
# File 'lib/activefacts/cql/compiler/expression.rb', line 181

def result_type_name(context)
  "compare#{operator}(#{[@e1,@e2].map{|e| e.player.name}*', '}))"
end

#to_sObject



212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# File 'lib/activefacts/cql/compiler/expression.rb', line 212

def to_s
  "compare#{
	    operator
	  }(#{
	    case @certainty
	    when nil; 'maybe '
	    when false; 'negated '
	    # else 'definitely '
	    end
  }#{
	    e1.to_s
	  } #{
	    e2.to_s
	  }#{
	    @qualifiers.empty? ? '' : ', ['+@qualifiers*', '+']'
	  })"
end