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 CHANGED
@@ -1 +1 @@
1
- 0.0.3
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 end
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
- # unidad simple
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
- # unidad compuesta
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
- # adimensional compound dimension... (special case)
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
- # unidad definida en función de otra
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
- # unidad simple definida en función de una expressión
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
- if definition.units.keys.size!=1
423
- raise ArgumentError,"To define a compound unit a dimension must be specified"
424
- end
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 "Se ha intentando redefinir #{unit_symbol} (previamente definido como #{UNITS[unit_symbol]}) como #{unit_def}"
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', :volume, u{dm**3}
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', :acceleration, u{9.80665*m/s**2}
652
+ define :g0, 'standard gravity', u{9.80665*m/s**2}
651
653
 
652
- define :bar, 'bar', :pressure, u{1E5*Pa}
653
- define :atm, 'atmosphere', :pressure, u{101325.0*Pa}
654
- define :mWC, 'meters of water column', :pressure, u{1E3*kg*g0/m**2}
655
- define :Torr, 'torricelli', :pressure, u{atm/760}
656
- define :mHg, 'mHg', :pressure, u{13.5951E3*kg*g0/m**2}
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', :force, u{g*g0} # kilopond kp = kgf
660
- define :lbf, 'pound-force', :force, u{lb*g0}
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', :volume, u{231*self.in**3}
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', :power, u{550*ft*lbf/s}
667
+ define :hp, 'horsepower', u{550*ft*lbf/s}
666
668
 
667
- define :psi, 'pounds-force per square inch', :pressure, u{lbf/self.in**2}
669
+ define :psi, 'pounds-force per square inch', u{lbf/self.in**2}
668
670
 
669
671
  end # Units
data/units-system.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{units-system}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Javier Goizueta"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: units-system
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Goizueta