Class: ActiveFacts::CQL::Compiler::Product

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

#bind, #conjunction, #identify_other_players, #identify_players_with_role_name, #is_equality_comparison, #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(*factors) ⇒ Product

Returns a new instance of Product.



278
279
280
# File 'lib/activefacts/cql/compiler/expression.rb', line 278

def initialize *factors
  @factors = factors
end

Instance Attribute Details

#factorsObject

Returns the value of attribute factors.



277
278
279
# File 'lib/activefacts/cql/compiler/expression.rb', line 277

def factors
  @factors
end

Instance Method Details

#identify_player(context) ⇒ Object



290
291
292
293
294
295
296
297
298
299
# File 'lib/activefacts/cql/compiler/expression.rb', line 290

def identify_player context
  @player || begin
    # The players in the @factors have already been identified
    # REVISIT: Calculate the units of the result from the units in @factors
    # REVISIT: The type of this result should be derived from type promotion rules. Here, we take the left-most.
    # REVISIT: We should define a subtype of the result type here, and apply the units to it.
    v = context.vocabulary
    @player = @factors[0].player
  end
end

#inspectObject

def result_value_type(context, name)

  vt = super
  # REVISIT: If there are units involved, create the result units
  vt
end


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

def inspect; to_s; end

#operatorObject



286
287
288
# File 'lib/activefacts/cql/compiler/expression.rb', line 286

def operator
  '*'
end

#refsObject



282
283
284
# File 'lib/activefacts/cql/compiler/expression.rb', line 282

def refs
  @factors
end

#result_type_name(context) ⇒ Object



301
302
303
# File 'lib/activefacts/cql/compiler/expression.rb', line 301

def result_type_name(context)
  "product(#{ @factors.map{|f| f.player.name}*', ' })"
end

#to_sObject



315
316
317
# File 'lib/activefacts/cql/compiler/expression.rb', line 315

def to_s
  'product(' + @factors.map{|factor| "#{factor.to_s}" } * ' ' + ')'
end