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

Returns a new instance of Sum.



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

def initialize *terms
  @terms = terms
end

Instance Attribute Details

#termsObject

Returns the value of attribute terms.



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

def terms
  @terms
end

Instance Method Details

#identify_player(context) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
# File 'lib/activefacts/cql/compiler/expression.rb', line 245

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


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

def inspect; to_s; end

#operatorObject



241
242
243
# File 'lib/activefacts/cql/compiler/expression.rb', line 241

def operator
  '+'
end

#refsObject



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

def refs
  @terms
end

#result_type_name(context) ⇒ Object



257
258
259
# File 'lib/activefacts/cql/compiler/expression.rb', line 257

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

#to_sObject



271
272
273
# File 'lib/activefacts/cql/compiler/expression.rb', line 271

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