Class: ActiveFacts::CQL::Compiler::Reciprocal

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_type_name, #result_value_type, #role_name, #side_effects, #trailing_adjective, #value_constraint

Constructor Details

#initialize(divisor) ⇒ Reciprocal

Returns a new instance of Reciprocal.



339
340
341
# File 'lib/activefacts/cql/compiler/expression.rb', line 339

def initialize divisor
  @divisor = divisor
end

Instance Attribute Details

#divisorObject

Returns the value of attribute divisor.



338
339
340
# File 'lib/activefacts/cql/compiler/expression.rb', line 338

def divisor
  @divisor
end

Instance Method Details

#compile(context) ⇒ Object



367
368
369
370
371
372
373
# File 'lib/activefacts/cql/compiler/expression.rb', line 367

def compile(context)
  op1 = @divisor.compile(context)
  context.vocabulary.constellation.Expression(
      :new, :expression_type => 'Unary', :operator => operator,
      :first_operand_expression => op1
  )
end

#identify_player(context) ⇒ Object



351
352
353
354
355
356
357
358
359
# File 'lib/activefacts/cql/compiler/expression.rb', line 351

def identify_player context
  @player || begin
    # The player in @divisor has already been identified
    # REVISIT: Calculate the units of the result from the units in @divisor
    # REVISIT: Do we want integer division?
    v = context.vocabulary
    @player = v.constellation.ValueType(v, 'Real', :concept => :new)
  end
end

#inspectObject



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

def inspect; to_s; end

#operatorObject



343
344
345
# File 'lib/activefacts/cql/compiler/expression.rb', line 343

def operator
  '1/'
end

#refsObject



347
348
349
# File 'lib/activefacts/cql/compiler/expression.rb', line 347

def refs
  [@divisor]
end

#to_sObject



363
364
365
# File 'lib/activefacts/cql/compiler/expression.rb', line 363

def to_s
  "RECIPROCAL(#{factor.to_s})"
end