Class: ActiveFacts::CQL::Compiler::Literal

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/cql/compiler/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(literal, unit) ⇒ Literal

Returns a new instance of Literal.



622
623
624
# File 'lib/activefacts/cql/compiler/expression.rb', line 622

def initialize literal, unit
  @literal, @unit = literal, unit
end

Instance Attribute Details

#clauseObject

Returns the value of attribute clause.



619
620
621
# File 'lib/activefacts/cql/compiler/expression.rb', line 619

def clause
  @clause
end

#leading_adjectiveObject (readonly)

Returns the value of attribute leading_adjective.



620
621
622
# File 'lib/activefacts/cql/compiler/expression.rb', line 620

def leading_adjective
  @leading_adjective
end

#literalObject

Returns the value of attribute literal.



619
620
621
# File 'lib/activefacts/cql/compiler/expression.rb', line 619

def literal
  @literal
end

#objectification_ofObject (readonly)

Returns the value of attribute objectification_of.



620
621
622
# File 'lib/activefacts/cql/compiler/expression.rb', line 620

def objectification_of
  @objectification_of
end

#roleObject

Returns the value of attribute role.



619
620
621
# File 'lib/activefacts/cql/compiler/expression.rb', line 619

def role
  @role
end

#role_refObject

Returns the value of attribute role_ref.



619
620
621
# File 'lib/activefacts/cql/compiler/expression.rb', line 619

def role_ref
  @role_ref
end

#trailing_adjectiveObject (readonly)

Returns the value of attribute trailing_adjective.



620
621
622
# File 'lib/activefacts/cql/compiler/expression.rb', line 620

def trailing_adjective
  @trailing_adjective
end

#unitObject

Returns the value of attribute unit.



619
620
621
# File 'lib/activefacts/cql/compiler/expression.rb', line 619

def unit
  @unit
end

#value_constraintObject (readonly)

Returns the value of attribute value_constraint.



620
621
622
# File 'lib/activefacts/cql/compiler/expression.rb', line 620

def value_constraint
  @value_constraint
end

Instance Method Details

#bind(context) ⇒ Object



662
663
664
665
666
667
668
# File 'lib/activefacts/cql/compiler/expression.rb', line 662

def bind context
  @binding || begin
    key = "#{@player.name} #{@literal}"
    @binding = (context.bindings[key] ||= Binding.new(@player))
    @binding.refs << self
  end
end

#bindingObject



670
671
672
# File 'lib/activefacts/cql/compiler/expression.rb', line 670

def binding
  @binding
end

#compile(context) ⇒ Object



674
675
676
677
678
679
680
681
682
# File 'lib/activefacts/cql/compiler/expression.rb', line 674

def compile(context)
  literal_string = case @literal
    when String; "'#{@literal.to_s}'"
    else @literal.to_s
    end
  context.vocabulary.constellation.Expression(
      :new, :expression_type => 'Literal', :literal_string => literal_string
  )
end

#identify_other_players(context) ⇒ Object



644
645
646
# File 'lib/activefacts/cql/compiler/expression.rb', line 644

def identify_other_players(context)
  identify_player context
end

#identify_player(context) ⇒ Object



648
649
650
651
652
653
654
655
656
657
658
659
660
# File 'lib/activefacts/cql/compiler/expression.rb', line 648

def identify_player context
  @player || begin
    player_name =
      case @literal
      when String; 'String'
      when Float; 'Real'
      when Numeric; 'Integer'
      when TrueClass, FalseClass; 'Boolean'
      end
    v = context.vocabulary
    @player = v.constellation.ValueType(v, player_name)
  end
end

#identify_players_with_role_name(context) ⇒ Object



640
641
642
# File 'lib/activefacts/cql/compiler/expression.rb', line 640

def identify_players_with_role_name(context)
  # Nothing to do here, move along
end

#inspectObject



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

def inspect; to_s; end

#nested_clausesObject



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

def nested_clauses; nil; end

#playerObject



636
637
638
# File 'lib/activefacts/cql/compiler/expression.rb', line 636

def player
  @player
end

#role_nameObject

Stubs:



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

def role_name; nil; end

#to_sObject



632
633
634
# File 'lib/activefacts/cql/compiler/expression.rb', line 632

def to_s
  unit ? "(#{@literal.to_s} in #{unit.to_s})" : @literal.to_s
end