Class: ActiveFacts::CQL::Compiler::Comparison
- Defined in:
- lib/activefacts/cql/compiler/expression.rb
Instance Attribute Summary collapse
-
#conjunction ⇒ Object
Returns the value of attribute conjunction.
-
#e1 ⇒ Object
Returns the value of attribute e1.
-
#e2 ⇒ Object
Returns the value of attribute e2.
-
#operator ⇒ Object
Returns the value of attribute operator.
-
#qualifiers ⇒ Object
Returns the value of attribute qualifiers.
Attributes inherited from Operation
#binding, #certainty, #clause, #fact_type, #player, #role, #role_ref
Instance Method Summary collapse
- #bind(context) ⇒ Object
- #compile(context) ⇒ Object
- #identify_player(context) ⇒ Object
-
#initialize(operator, e1, e2, certainty = true) ⇒ Comparison
constructor
A new instance of Comparison.
- #inspect ⇒ Object
- #is_equality_comparison ⇒ Object
- #refs ⇒ Object
- #result_type_name(context) ⇒ Object
- #to_s ⇒ Object
Methods inherited from Operation
#identify_other_players, #identify_players_with_role_name, #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.
153 154 155 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 153 def initialize operator, e1, e2, certainty = true @operator, @e1, @e2, @certainty, @qualifiers = operator, e1, e2, certainty, [] end |
Instance Attribute Details
#conjunction ⇒ Object
Returns the value of attribute conjunction.
151 152 153 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 151 def conjunction @conjunction end |
#e1 ⇒ Object
Returns the value of attribute e1.
151 152 153 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 151 def e1 @e1 end |
#e2 ⇒ Object
Returns the value of attribute e2.
151 152 153 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 151 def e2 @e2 end |
#operator ⇒ Object
Returns the value of attribute operator.
151 152 153 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 151 def operator @operator end |
#qualifiers ⇒ Object
Returns the value of attribute qualifiers.
151 152 153 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 151 def qualifiers @qualifiers end |
Instance Method Details
#bind(context) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 161 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 |
#compile(context) ⇒ Object
218 219 220 221 222 223 224 225 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 218 def compile(context) op1 = e1.compile(context) op2 = e2.compile(context) context.vocabulary.constellation.Expression( :new, :expression_type => 'Binary', :operator => operator, :first_operand_expression => op1, :second_operand_expression => op2 ) end |
#identify_player(context) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 185 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 |
#inspect ⇒ Object
198 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 198 def inspect; to_s; end |
#is_equality_comparison ⇒ Object
181 182 183 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 181 def is_equality_comparison @operator == '=' end |
#refs ⇒ Object
157 158 159 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 157 def refs [@e1, @e2] end |
#result_type_name(context) ⇒ Object
177 178 179 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 177 def result_type_name(context) "COMPARE#{operator}<#{[@e1,@e2].map{|e| e.player.name}*' WITH '})>" end |
#to_s ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 200 def to_s "COMPARE#{ operator }(#{ case @certainty when nil; 'maybe ' when false; 'negated ' # else 'definitely ' end }#{ e1.to_s } WITH #{ e2.to_s }#{ @qualifiers.empty? ? '' : ', ['+@qualifiers*', '+']' })" end |