Class: ActiveFacts::CQL::Compiler::Product
- Inherits:
-
Operation
- Object
- Operation
- ActiveFacts::CQL::Compiler::Product
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
#bind, #conjunction, #identify_other_players, #identify_players_with_role_name, #is_equality_comparison, #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(*factors) ⇒ Product
Returns a new instance of Product.
285
286
287
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 285
def initialize *factors
@factors = factors
end
|
Instance Attribute Details
#factors ⇒ Object
Returns the value of attribute factors.
284
285
286
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 284
def factors
@factors
end
|
Instance Method Details
#compile(context) ⇒ Object
318
319
320
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 318
def compile(context)
compile_factors(context, @factors)
end
|
#compile_factors(context, factors) ⇒ Object
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 322
def compile_factors(context, factors)
if factors.size == 1
factors[0].compile(context)
else
lhs = factors.shift
lhs_expr = lhs.compile(context)
rhs_expr = compile_factors(context, factors)
context.vocabulary.constellation.Expression(
:new, :expression_type => 'Binary', :operator => operator,
:first_operand_expression => lhs_expr, :second_operand_expression => rhs_expr
)
end
end
|
#identify_player(context) ⇒ Object
297
298
299
300
301
302
303
304
305
306
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 297
def identify_player context
@player || begin
v = context.vocabulary
@player = @factors[0].player
end
end
|
#inspect ⇒ Object
312
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 312
def inspect; to_s; end
|
#operator ⇒ Object
293
294
295
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 293
def operator
'*'
end
|
#refs ⇒ Object
289
290
291
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 289
def refs
@factors
end
|
#result_type_name(context) ⇒ Object
308
309
310
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 308
def result_type_name(context)
"PRODUCT_OF<#{ @factors.map{|f| f.player.name}*' ' }>"
end
|
#to_s ⇒ Object
314
315
316
|
# File 'lib/activefacts/cql/compiler/expression.rb', line 314
def to_s
'PRODUCT(' + @factors.map{|factor| "#{factor.to_s}" } * ' TIMES ' + ')'
end
|