Class: ActiveFacts::CQL::Compiler::Sum

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_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(*terms) ⇒ Sum

Returns a new instance of Sum.



229
230
231
# File 'lib/activefacts/cql/compiler/expression.rb', line 229

def initialize *terms
  @terms = terms
end

Instance Attribute Details

#termsObject

Returns the value of attribute terms.



228
229
230
# File 'lib/activefacts/cql/compiler/expression.rb', line 228

def terms
  @terms
end

Instance Method Details

#identify_player(context) ⇒ Object



241
242
243
244
245
246
247
248
249
250
251
# File 'lib/activefacts/cql/compiler/expression.rb', line 241

def identify_player context
  @player || begin
    # The players in the @terms have already been identified
    # REVISIT: Check compliance of all units in @terms, and apply conversions where necessary
    # 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 = @terms[0].player
    @player
  end
end

#inspectObject

def result_value_type(context, name)

  # REVISIT: If there are units involved, check compatibility
  vt = super
  vt
end


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

def inspect; to_s; end

#operatorObject



237
238
239
# File 'lib/activefacts/cql/compiler/expression.rb', line 237

def operator
  '+'
end

#refsObject



233
234
235
# File 'lib/activefacts/cql/compiler/expression.rb', line 233

def refs
  @terms
end

#result_type_name(context) ⇒ Object



253
254
255
# File 'lib/activefacts/cql/compiler/expression.rb', line 253

def result_type_name(context)
  "SUM_OF<#{ @terms.map{|f| f.player.name}*', ' }>"
end

#to_sObject



267
268
269
# File 'lib/activefacts/cql/compiler/expression.rb', line 267

def to_s
  'SUM(' + @terms.map{|term| "#{term.to_s}" } * ' PLUS ' + ')'
end