units-system 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/units-system.rb +26 -24
- data/units-system.gemspec +1 -1
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/units-system.rb
CHANGED
@@ -76,7 +76,8 @@ module Units
|
|
76
76
|
break
|
77
77
|
end
|
78
78
|
end
|
79
|
-
Measure.new mag, units
|
79
|
+
Measure.new mag, units
|
80
|
+
end
|
80
81
|
|
81
82
|
# decompose to base units
|
82
83
|
def base
|
@@ -384,7 +385,7 @@ module Units
|
|
384
385
|
if args.first.kind_of?(Symbol)
|
385
386
|
dim = args.shift
|
386
387
|
if args.first.kind_of?(Numeric)
|
387
|
-
#
|
388
|
+
# simple units
|
388
389
|
factor = args.shift
|
389
390
|
factor_units = args.shift
|
390
391
|
if factor_units
|
@@ -396,19 +397,19 @@ module Units
|
|
396
397
|
equivalence = factor*ud.decomposition if ud.decomposition
|
397
398
|
factor *= ud.factor
|
398
399
|
end
|
399
|
-
# si_unit = (factor==1.0) # to save si_units definitions
|
400
|
+
# si_unit = (factor==1.0) # to save si_units definitions # TODO: tolerance?
|
400
401
|
else
|
401
|
-
#
|
402
|
+
# compound unit
|
402
403
|
equivalence = args.shift
|
403
404
|
factor = equivalence.to_si.magnitude
|
404
405
|
si_unit = (factor==1.0) # TODO: tolerance?
|
405
406
|
if equivalence.units.empty?
|
406
|
-
#
|
407
|
+
# dimensionless compound dimension... (special case for angular units)
|
407
408
|
equivalence = nil
|
408
409
|
end
|
409
410
|
end
|
410
411
|
elsif args.first.kind_of?(Numeric)
|
411
|
-
#
|
412
|
+
# unit define in terms of other unit
|
412
413
|
factor = args.shift
|
413
414
|
factor_units = args.shift
|
414
415
|
u = unit(factor_units)
|
@@ -417,17 +418,18 @@ module Units
|
|
417
418
|
factor *= u.factor
|
418
419
|
bias = args.shift
|
419
420
|
else
|
420
|
-
#
|
421
|
+
# unit defined from a measure expression; the dimension must be already known or defined
|
422
|
+
# here (as as symbol preceding the expression).
|
421
423
|
definition = args.shift
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
dim = definition.units.keys.first
|
424
|
+
dim = definition.dimension
|
425
|
+
raise ArgumentError,"To define a new compound unit a dimension must be specified" unless dim
|
426
|
+
equivalence = definition
|
426
427
|
factor = definition.to_si.magnitude
|
428
|
+
# si_unit = (factor==1.0) # to save si_units definitions # TODO: tolerance?
|
427
429
|
end
|
428
430
|
unit_def = UnitDefinition.new(dim, factor, name, equivalence, bias)
|
429
431
|
if UNITS.has_key?(unit_symbol)
|
430
|
-
raise "
|
432
|
+
raise "Redefinition of #{unit_symbol} as #{unit_def} (previously defined as #{UNITS[unit_symbol]})"
|
431
433
|
end
|
432
434
|
UNITS[unit_symbol] = unit_def
|
433
435
|
System.define unit_symbol
|
@@ -636,7 +638,7 @@ module Units
|
|
636
638
|
define :°F, 'degree Fahrenheit', 5.0/9.0, :K, +459.67
|
637
639
|
define :R, 'rankine', 5.0/9.0, :K
|
638
640
|
|
639
|
-
define :l, 'litre',
|
641
|
+
define :l, 'litre', u{dm**3}
|
640
642
|
define :L, 'litre', 1, :l
|
641
643
|
|
642
644
|
define :°, 'degree', ::Math::PI/180.0, :rad
|
@@ -647,23 +649,23 @@ module Units
|
|
647
649
|
define :arcmin, 'arc-minute', 1, :′
|
648
650
|
define :arcsec, 'arc-second', 1, :″
|
649
651
|
|
650
|
-
define :g0, 'standard gravity',
|
652
|
+
define :g0, 'standard gravity', u{9.80665*m/s**2}
|
651
653
|
|
652
|
-
define :bar, 'bar',
|
653
|
-
define :atm, 'atmosphere',
|
654
|
-
define :mWC, 'meters of water column',
|
655
|
-
define :Torr, 'torricelli',
|
656
|
-
define :mHg, 'mHg',
|
654
|
+
define :bar, 'bar', 1E5, :Pa
|
655
|
+
define :atm, 'atmosphere', 101325.0, :Pa
|
656
|
+
define :mWC, 'meters of water column', u{1E3*kg*g0/m**2}
|
657
|
+
define :Torr, 'torricelli', u{atm/760}
|
658
|
+
define :mHg, 'mHg', u{13.5951E3*kg*g0/m**2}
|
657
659
|
|
658
660
|
# define :kp, 'kilopond', :force, u{kg*g0} # or define pond?
|
659
|
-
define :gf, 'gram-force',
|
660
|
-
define :lbf, 'pound-force',
|
661
|
+
define :gf, 'gram-force', u{g*g0} # kilopond kp = kgf
|
662
|
+
define :lbf, 'pound-force', u{lb*g0}
|
661
663
|
|
662
664
|
define :dyn, 'dyne', 10, :µN # u{1*g*cm/s**2}
|
663
|
-
define :galUS, 'U.S. liquid gallon',
|
665
|
+
define :galUS, 'U.S. liquid gallon', u{231*self.in**3}
|
664
666
|
define :galUK, 'Imperial gallon', 4.546092, :l
|
665
|
-
define :hp, 'horsepower',
|
667
|
+
define :hp, 'horsepower', u{550*ft*lbf/s}
|
666
668
|
|
667
|
-
define :psi, 'pounds-force per square inch',
|
669
|
+
define :psi, 'pounds-force per square inch', u{lbf/self.in**2}
|
668
670
|
|
669
671
|
end # Units
|
data/units-system.gemspec
CHANGED