Class: ActiveFacts::Metamodel::Unit
- Inherits:
-
Object
- Object
- ActiveFacts::Metamodel::Unit
- Defined in:
- lib/activefacts/generate/cql.rb,
lib/activefacts/vocabulary/metamodel.rb,
lib/activefacts/vocabulary/extensions.rb
Instance Method Summary collapse
Instance Method Details
#as_cql ⇒ Object
667 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 |
# File 'lib/activefacts/generate/cql.rb', line 667 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 |
#describe ⇒ Object
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/activefacts/vocabulary/extensions.rb', line 170 def describe 'Unit' + name + (plural_name ? '/'+plural_name : '') + '=' + coefficient.to_s+'*' + all_derivation_as_derived_unit.map do |derivation| derivation.base_unit.name + (derivation.exponent != 1 ? derivation.exponent.to_s : '') end.join('') + (offset ? ' + '+offset.to_s : '') end |