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
- #identify_player(context) ⇒ Object
-
#initialize(operator, e1, e2, certainty = true) ⇒ Comparison
constructor
A new instance of Comparison.
-
#inspect ⇒ Object
def project lr @projection = lr projected_rr = lr == :left ? @e2 : @e1 true end.
- #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_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
#conjunction ⇒ Object
Returns the value of attribute conjunction.
155 156 157 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 155 def conjunction @conjunction end |
#e1 ⇒ Object
Returns the value of attribute e1.
155 156 157 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 155 def e1 @e1 end |
#e2 ⇒ Object
Returns the value of attribute e2.
155 156 157 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 155 def e2 @e2 end |
#operator ⇒ Object
Returns the value of attribute operator.
155 156 157 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 155 def operator @operator end |
#qualifiers ⇒ Object
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 |
#inspect ⇒ Object
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_comparison ⇒ Object
185 186 187 |
# File 'lib/activefacts/cql/compiler/expression.rb', line 185 def is_equality_comparison @operator == '=' end |
#refs ⇒ Object
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_s ⇒ Object
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 |