Class: ActiveFacts::CQL::Compiler::ValueConstraint
- Inherits:
-
Constraint
- Object
- Definition
- Constraint
- ActiveFacts::CQL::Compiler::ValueConstraint
- Defined in:
- lib/activefacts/cql/compiler/constraint.rb
Instance Attribute Summary
Attributes inherited from Definition
#constellation, #tree, #vocabulary
Instance Method Summary collapse
- #assert_value(val) ⇒ Object
- #compile ⇒ Object
-
#initialize(ast, enforcement) ⇒ ValueConstraint
constructor
A new instance of ValueConstraint.
- #to_s ⇒ Object
- #vrto_s(vr) ⇒ Object
Methods inherited from Constraint
#bind_clauses, #common_bindings, #loose_bind, #loose_bind_wherever_possible, #loose_binding, #warn_ignored_queries
Methods inherited from Definition
#all_bindings_in_clauses, #build_all_steps, #build_step, #build_variables, #source
Constructor Details
#initialize(ast, enforcement) ⇒ ValueConstraint
Returns a new instance of ValueConstraint.
514 515 516 517 518 519 |
# File 'lib/activefacts/cql/compiler/constraint.rb', line 514 def initialize ast, enforcement super nil, enforcement @value_ranges = ast[:ranges] @units = ast[:units] @regular_expression = ast[:regular_expression] end |
Instance Method Details
#assert_value(val) ⇒ Object
521 522 523 524 525 526 527 528 529 |
# File 'lib/activefacts/cql/compiler/constraint.rb', line 521 def assert_value(val) if val.is_a?(String) @constellation.Value(eval(val), true, nil) elsif val @constellation.Value(val.to_s, false , nil) else nil end end |
#compile ⇒ Object
531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 |
# File 'lib/activefacts/cql/compiler/constraint.rb', line 531 def compile @constraint = @constellation.ValueConstraint(:new) raise "Units on value constraints are not yet processed (at line #{'REVISIT'})" if @units # @string.line_of(node.interval.first) if @value_ranges @value_ranges.each do |range| min, max = Array === range ? range : [range, range] v_range = @constellation.ValueRange( min && @constellation.Bound(:value => assert_value(min), :is_inclusive => true), max && @constellation.Bound(:value => assert_value(max), :is_inclusive => true)) ar = @constellation.AllowedRange(@constraint, v_range) end else @constraint.regular_expression = @regular_expression end @enforcement.compile(@constellation, @constraint) if @enforcement super end |
#to_s ⇒ Object
569 570 571 572 573 574 575 |
# File 'lib/activefacts/cql/compiler/constraint.rb', line 569 def to_s "#{super} to " + (@value_ranges ? "(#{@value_ranges.map{|vr| vrto_s(vr) }.inspect })#{ @units ? " in #{@units.inspect}" : ''}" : @regular_expression ) end |
#vrto_s(vr) ⇒ Object
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 |
# File 'lib/activefacts/cql/compiler/constraint.rb', line 551 def vrto_s vr if Array === vr min = vr[0] max = vr[1] if Numeric === min or Numeric === max infinite = 1.0/0 min ||= -infinite max ||= infinite else min ||= 'MIN' max ||= 'MAX' end Range.new(min, max) else vr end end |