Class: ActiveFacts::Metamodel::Unit

Inherits:
Object
  • Object
show all
Defined in:
lib/activefacts/generate/cql.rb,
lib/activefacts/vocabulary/metamodel.rb

Instance Method Summary collapse

Instance Method Details

#as_cqlObject



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
# File 'lib/activefacts/generate/cql.rb', line 644

def as_cql
  if !ephemera_url
    if coefficient
      # REVISIT: Use a smarter algorithm to switch to exponential form when there'd be lots of zeroes.
      coefficient.numerator.to_s('F') +

      if d = coefficient.denominator and d != 1
        "/#{d}"
	    else
 ''
      end +

      ' '
    else
      '1 '
    end
	else
	  ''
  end +

	all_derivation_as_derived_unit.
	  sort_by{|d| d.base_unit.name}.
    # REVISIT: Sort base units
    # REVISIT: convert negative powers to division?
    map do |der|
      base = der.base_unit
      "#{base.name}#{der.exponent and der.exponent != 1 ? "^#{der.exponent}" : ''} "
    end*'' +

  if o = offset and o != 0
    "+ #{o.to_s('F')} "
	else
	  ''
  end +

  "converts to #{name}#{plural_name ? '/'+plural_name : ''}" +

	(coefficient && !coefficient.is_precise ?  ' approximately' : '') +

	(ephemera_url ? " ephemera #{ephemera_url}" : '') +

  ';'
end