Class: ActiveFacts::Metamodel::Unit

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

Instance Method Summary collapse

Instance Method Details

#as_cqlObject



668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
# File 'lib/activefacts/generators/cql.rb', line 668

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