Class: ActiveFacts::CQL::Compiler::LogicalAnd

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(*factors) ⇒ LogicalAnd

Returns a new instance of LogicalAnd.



444
445
446
# File 'lib/activefacts/cql/compiler/expression.rb', line 444

def initialize *factors
  @factors = factors
end

Instance Attribute Details

#factorsObject

Returns the value of attribute factors.



443
444
445
# File 'lib/activefacts/cql/compiler/expression.rb', line 443

def factors
  @factors
end

Instance Method Details

#compile(context) ⇒ Object



473
474
475
# File 'lib/activefacts/cql/compiler/expression.rb', line 473

def compile(context)
  compile_factors(context, @factors)
end

#compile_factors(context, factors) ⇒ Object



477
478
479
480
481
482
483
484
485
486
487
488
489
# File 'lib/activefacts/cql/compiler/expression.rb', line 477

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



456
457
458
459
460
461
# File 'lib/activefacts/cql/compiler/expression.rb', line 456

def identify_player context
  @player || begin
    v = context.vocabulary
    @player = @factors[0].player
  end
end

#inspectObject



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

def inspect; to_s; end

#operatorObject



452
453
454
# File 'lib/activefacts/cql/compiler/expression.rb', line 452

def operator
  'and'
end

#refsObject



448
449
450
# File 'lib/activefacts/cql/compiler/expression.rb', line 448

def refs
  @factors
end

#result_type_name(context) ⇒ Object



463
464
465
# File 'lib/activefacts/cql/compiler/expression.rb', line 463

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

#to_sObject



469
470
471
# File 'lib/activefacts/cql/compiler/expression.rb', line 469

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