class ActiveFacts::Metamodel::Unit

Public Instance Methods

as_cql() click to toggle source
# File lib/activefacts/generators/cql.rb, line 670
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