ruby-units 1.3.2 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/CHANGELOG.txt +25 -7
  2. data/LICENSE.txt +1 -1
  3. data/README.md +68 -55
  4. data/RakeFile +27 -18
  5. data/TODO +2 -1
  6. data/VERSION +1 -1
  7. data/lib/ruby-units.rb +2 -2
  8. data/lib/ruby_units.rb +2 -2
  9. data/lib/ruby_units/array.rb +4 -2
  10. data/lib/ruby_units/date.rb +17 -4
  11. data/lib/ruby_units/definition.rb +100 -0
  12. data/lib/ruby_units/fixnum.rb +6 -4
  13. data/lib/ruby_units/math.rb +32 -2
  14. data/lib/ruby_units/numeric.rb +2 -1
  15. data/lib/ruby_units/object.rb +8 -1
  16. data/lib/ruby_units/string.rb +10 -109
  17. data/lib/ruby_units/string/extra.rb +45 -11
  18. data/lib/ruby_units/time.rb +11 -2
  19. data/lib/ruby_units/unit.rb +722 -434
  20. data/lib/ruby_units/unit_definitions.rb +3 -252
  21. data/lib/ruby_units/unit_definitions/base.rb +103 -0
  22. data/lib/ruby_units/unit_definitions/prefix.rb +40 -0
  23. data/lib/ruby_units/unit_definitions/standard.rb +705 -0
  24. data/lib/ruby_units/version.rb +1 -0
  25. data/ruby-units.gemspec +15 -20
  26. metadata +46 -35
  27. data/Gemfile +0 -12
  28. data/Manifest.txt +0 -19
  29. data/autotest/discover.rb +0 -1
  30. data/spec/ruby-units/array_spec.rb +0 -14
  31. data/spec/ruby-units/complex_spec.rb +0 -37
  32. data/spec/ruby-units/date_spec.rb +0 -38
  33. data/spec/ruby-units/math_spec.rb +0 -63
  34. data/spec/ruby-units/numeric_spec.rb +0 -12
  35. data/spec/ruby-units/object_spec.rb +0 -7
  36. data/spec/ruby-units/string/extra_spec.rb +0 -45
  37. data/spec/ruby-units/string_spec.rb +0 -20
  38. data/spec/ruby-units/time_spec.rb +0 -28
  39. data/spec/ruby-units/unit_spec.rb +0 -965
  40. data/spec/spec_helper.rb +0 -5
  41. data/test/test_cache.rb +0 -26
  42. data/test/test_ruby-units.rb +0 -976
@@ -1,252 +1,3 @@
1
- class Unit < Numeric
2
- UNIT_DEFINITIONS = {
3
- # prefixes
4
- '<googol>' => [%w{googol}, 1e100, :prefix],
5
- '<kibi>' => [%w{Ki Kibi kibi}, 2**10, :prefix],
6
- '<mebi>' => [%w{Mi Mebi mebi}, 2**20, :prefix],
7
- '<gibi>' => [%w{Gi Gibi gibi}, 2**30, :prefix],
8
- '<tebi>' => [%w{Ti Tebi tebi}, 2**40, :prefix],
9
- '<pebi>' => [%w{Pi Pebi pebi}, 2**50, :prefix],
10
- '<exi>' => [%w{Ei Exi exi}, 2**60, :prefix],
11
- '<zebi>' => [%w{Zi Zebi zebi}, 2**70, :prefix],
12
- '<yebi>' => [%w{Yi Yebi yebi}, 2**80, :prefix],
13
- '<yotta>' => [%w{Y Yotta yotta}, 1e24, :prefix],
14
- '<zetta>' => [%w{Z Zetta zetta}, 1e21, :prefix],
15
- '<exa>' => [%w{E Exa exa}, 1e18, :prefix],
16
- '<peta>' => [%w{P Peta peta}, 1e15, :prefix],
17
- '<tera>' => [%w{T Tera tera}, 1e12, :prefix],
18
- '<giga>' => [%w{G Giga giga}, 1e9, :prefix],
19
- '<mega>' => [%w{M Mega mega}, 1e6, :prefix],
20
- '<kilo>' => [%w{k kilo}, 1e3, :prefix],
21
- '<hecto>' => [%w{h Hecto hecto}, 1e2, :prefix],
22
- '<deca>' => [%w{da Deca deca deka}, 1e1, :prefix],
23
- '<deci>' => [%w{d Deci deci}, Rational(1,1e1), :prefix],
24
- '<centi>' => [%w{c Centi centi}, Rational(1,1e2), :prefix],
25
- '<milli>' => [%w{m Milli milli}, Rational(1,1e3), :prefix],
26
- '<micro>' => [%w{u Micro micro}, Rational(1,1e6), :prefix],
27
- '<nano>' => [%w{n Nano nano}, Rational(1,1e9), :prefix],
28
- '<pico>' => [%w{p Pico pico}, Rational(1,1e12), :prefix],
29
- '<femto>' => [%w{f Femto femto}, Rational(1,1e15), :prefix],
30
- '<atto>' => [%w{a Atto atto}, Rational(1,1e18), :prefix],
31
- '<zepto>' => [%w{z Zepto zepto}, Rational(1,1e21), :prefix],
32
- '<yocto>' => [%w{y Yocto yocto}, Rational(1,1e24), :prefix],
33
- '<1>' => [%w{1},1,:prefix],
34
-
35
- # length units
36
- '<meter>' => [%w{m meter meters metre metres}, 1, :length, %w{<meter>} ],
37
- '<inch>' => [%w{in inch inches "}, Rational(254,10_000), :length, %w{<meter>}],
38
- '<foot>' => [%w{ft foot feet '}, Rational(3048,10_000), :length, %w{<meter>}],
39
- '<yard>' => [%w{yd yard yards}, 0.9144, :length, %w{<meter>}],
40
- '<mile>' => [%w{mi mile miles}, 1609.344, :length, %w{<meter>}],
41
- '<naut-mile>' => [%w{nmi}, 1852, :length, %w{<meter>}],
42
- '<league>'=> [%w{league leagues}, 4828, :length, %w{<meter>}],
43
- '<furlong>'=> [%w{furlong furlongs}, 201.2, :length, %w{<meter>}],
44
- '<rod>' => [%w{rd rod rods}, 5.029, :length, %w{<meter>}],
45
- '<mil>' => [%w{mil mils}, 0.0000254, :length, %w{<meter>}],
46
- '<angstrom>' =>[%w{ang angstrom angstroms}, Rational(1,1e10), :length, %w{<meter>}],
47
- '<fathom>' => [%w{fathom fathoms}, 1.829, :length, %w{<meter>}],
48
- '<pica>' => [%w{pica picas}, 0.004217, :length, %w{<meter>}],
49
- '<point>' => [%w{pt point points}, 0.0003514, :length, %w{<meter>}],
50
- '<redshift>' => [%w{z red-shift}, 1.302773e26, :length, %w{<meter>}],
51
- '<AU>' => [%w{AU astronomical-unit}, 149597900000, :length, %w{<meter>}],
52
- '<light-second>'=>[%w{ls light-second}, 299792500, :length, %w{<meter>}],
53
- '<light-minute>'=>[%w{lmin light-minute}, 17987550000, :length, %w{<meter>}],
54
- '<light-year>' => [%w{ly light-year}, 9460528000000000, :length, %w{<meter>}],
55
- '<parsec>' => [%w{pc parsec parsecs}, 30856780000000000, :length, %w{<meter>}],
56
-
57
- #mass
58
- '<kilogram>' => [%w{kg kilogram kilograms}, 1, :mass, %w{<kilogram>}],
59
- '<AMU>' => [%w{u AMU amu}, 6.0221415e26, :mass, %w{<kilogram>}],
60
- '<dalton>' => [%w{Da Dalton Daltons dalton daltons}, 6.0221415e26, :mass, %w{<kilogram>}],
61
- '<slug>' => [%w{slug slugs}, 14.5939029, :mass, %w{<kilogram>}],
62
- '<short-ton>' => [%w{tn ton}, 907.18474, :mass, %w{<kilogram>}],
63
- '<metric-ton>'=>[%w{tonne}, 1000, :mass, %w{<kilogram>}],
64
- '<carat>' => [%w{ct carat carats}, 0.0002, :mass, %w{<kilogram>}],
65
- '<pound>' => [%w{lbs lb pound pounds #}, Rational(8171193714040401,18014398509481984), :mass, %w{<kilogram>}],
66
- '<ounce>' => [%w{oz ounce ounces}, Rational(8171193714040401,288230376151711744), :mass, %w{<kilogram>}],
67
- '<gram>' => [%w{g gram grams gramme grammes},Rational(1,1e3),:mass, %w{<kilogram>}],
68
-
69
- #area
70
- '<hectare>'=>[%w{hectare}, 10000, :area, %w{<meter> <meter>}],
71
- '<acre>'=>[%w(acre acres), 4046.85642, :area, %w{<meter> <meter>}],
72
- '<sqft>'=>[%w(sqft), 1, :area, %w{<feet> <feet>}],
73
-
74
- #volume
75
- '<liter>' => [%w{l L liter liters litre litres}, Rational(1,1e3), :volume, %w{<meter> <meter> <meter>}],
76
- '<gallon>'=> [%w{gal gallon gallons}, 0.0037854118, :volume, %w{<meter> <meter> <meter>}],
77
- '<quart>'=> [%w{qt quart quarts}, 0.00094635295, :volume, %w{<meter> <meter> <meter>}],
78
- '<pint>'=> [%w{pt pint pints}, 0.000473176475, :volume, %w{<meter> <meter> <meter>}],
79
- '<cup>'=> [%w{cu cup cups}, 0.000236588238, :volume, %w{<meter> <meter> <meter>}],
80
- '<fluid-ounce>'=> [%w{floz fluid-ounce}, 2.95735297e-5, :volume, %w{<meter> <meter> <meter>}],
81
- '<tablespoon>'=> [%w{tbs tablespoon tablespoons}, 1.47867648e-5, :volume, %w{<meter> <meter> <meter>}],
82
- '<teaspoon>'=> [%w{tsp teaspoon teaspoons}, 4.92892161e-6, :volume, %w{<meter> <meter> <meter>}],
83
-
84
- #volumetric flow
85
- '<cfm>' => [%w{cfm CFM CFPM}, (18435447/39062500000), :volumetric_flow, %w{<meter> <meter> <meter>}, %w{<second>}],
86
-
87
- #speed
88
- '<kph>' => [%w{kph}, 0.277777778, :speed, %w{<meter>}, %w{<second>}],
89
- '<mph>' => [%w{mph}, 0.44704, :speed, %w{<meter>}, %w{<second>}],
90
- '<knot>' => [%w{kt kn kts knot knots}, 0.514444444, :speed, %w{<meter>}, %w{<second>}],
91
- '<fps>' => [%w{fps}, 0.3048, :speed, %w{<meter>}, %w{<second>}],
92
-
93
- #acceleration
94
- '<gee>' => [%w{gee}, 9.80655, :acceleration, %w{<meter>}, %w{<second> <second>}],
95
-
96
-
97
- #temperature_difference
98
- '<kelvin>' => [%w{degK kelvin}, 1, :temperature, %w{<kelvin>}],
99
- '<celsius>' => [%w{degC celsius celsius centigrade}, 1, :temperature, %w{<kelvin>}],
100
- '<fahrenheit>' => [%w{degF fahrenheit}, Rational(1,1.8), :temperature, %w{<kelvin>}],
101
- '<rankine>' => [%w{degR rankine}, Rational(1,1.8), :temperature, %w{<kelvin>}],
102
- '<tempK>' => [%w{tempK}, 1, :temperature, %w{<tempK>}],
103
- '<tempC>' => [%w{tempC}, 1, :temperature, %w{<tempK>}],
104
- '<tempF>' => [%w{tempF}, Rational(1,1.8), :temperature, %w{<tempK>}],
105
- '<tempR>' => [%w{tempR}, Rational(1,1.8), :temperature, %w{<tempK>}],
106
-
107
- #time
108
- '<second>'=> [%w{s sec second seconds}, 1, :time, %w{<second>}],
109
- '<minute>'=> [%w{min minute minutes}, 60, :time, %w{<second>}],
110
- '<hour>'=> [%w{h hr hrs hour hours}, 3600, :time, %w{<second>}],
111
- '<day>'=> [%w{d day days}, 3600*24, :time, %w{<second>}],
112
- '<week>'=> [%w{wk week weeks}, 7*3600*24, :time, %w{<second>}],
113
- '<fortnight>'=> [%w{fortnight fortnights}, 1209600, :time, %W{<second>}],
114
- '<year>'=> [%w{y yr year years annum}, 31556926, :time, %w{<second>}],
115
- '<decade>'=>[%w{decade decades}, 315569260, :time, %w{<second>}],
116
- '<century>'=>[%w{century centuries}, 3155692600, :time, %w{<second>}],
117
-
118
- #pressure
119
- '<pascal>' => [%w{Pa pascal Pascal}, 1, :pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
120
- '<bar>' => [%w{bar bars}, 100000, :pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
121
- '<mmHg>' => [%w{mmHg}, 133.322368,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
122
- '<inHg>' => [%w{inHg}, 3386.3881472,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
123
- '<torr>' => [%w{torr}, 133.322368,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
124
- '<bar>' => [%w{bar}, 100000,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
125
- '<atm>' => [%w{atm ATM atmosphere atmospheres}, 101325,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
126
- '<psi>' => [%w{psi}, 6894.76,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
127
- '<cmh2o>' => [%w{cmH2O}, 98.0638,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
128
- '<inh2o>' => [%w{inH2O}, 249.082052,:pressure, %w{<kilogram>},%w{<meter> <second> <second>}],
129
-
130
- #viscosity
131
- '<poise>' => [%w{P poise}, Rational(1,10), :viscosity, %w{<kilogram>},%w{<meter> <second>} ],
132
- '<stokes>' => [%w{St stokes}, Rational(1,1e4), :viscosity, %w{<meter> <meter>}, %w{<second>}],
133
-
134
- #substance
135
- '<mole>' => [%w{mol mole}, 1, :substance, %w{<mole>}],
136
-
137
- #concentration
138
- '<molar>' => [%w{M molar}, 1000, :concentration, %w{<mole>}, %w{<meter> <meter> <meter>}],
139
- '<wtpercent>' => [%w{wt% wtpercent}, 10, :concentration, %w{<kilogram>}, %w{<meter> <meter> <meter>}],
140
-
141
- #activity
142
- '<katal>' => [%w{kat katal Katal}, 1, :activity, %w{<mole>}, %w{<second>}],
143
- '<unit>' => [%w{U enzUnit}, 16.667e-16, :activity, %w{<mole>}, %w{<second>}],
144
-
145
- #capacitance
146
- '<farad>' => [%w{F farad Farad}, 1, :capacitance, %w{<second> <second> <second> <second> <ampere> <ampere>}, %w{<kilogram> <meter> <meter>}],
147
-
148
- #charge
149
- '<coulomb>' => [%w{C coulomb Coulomb}, 1, :charge, %w{<ampere> <second>}],
150
-
151
- #current
152
- '<ampere>' => [%w{A Ampere ampere amp amps}, 1, :current, %w{<ampere>}],
153
-
154
- #conductance
155
- '<siemens>' => [%w{S Siemens siemens}, 1, :resistance, %w{<second> <second> <second> <ampere> <ampere>}, %w{<kilogram> <meter> <meter>}],
156
-
157
- #inductance
158
- '<henry>' => [%w{H Henry henry}, 1, :inductance, %w{<meter> <meter> <kilogram>}, %w{<second> <second> <ampere> <ampere>}],
159
-
160
- #potential
161
- '<volt>' => [%w{V Volt volt volts}, 1, :potential, %w{<meter> <meter> <kilogram>}, %w{<second> <second> <second> <ampere>}],
162
-
163
- #resistance
164
- '<ohm>' => [%w{Ohm ohm}, 1, :resistance, %w{<meter> <meter> <kilogram>},%w{<second> <second> <second> <ampere> <ampere>}],
165
-
166
- #magnetism
167
- '<weber>' => [%w{Wb weber webers}, 1, :magnetism, %w{<meter> <meter> <kilogram>}, %w{<second> <second> <ampere>}],
168
- '<tesla>' => [%w{T tesla teslas}, 1, :magnetism, %w{<kilogram>}, %w{<second> <second> <ampere>}],
169
- '<gauss>' => [%w{G gauss}, Rational(1,1e4), :magnetism, %w{<kilogram>}, %w{<second> <second> <ampere>}],
170
- '<maxwell>' => [%w{Mx maxwell maxwells}, Rational(1,1e8), :magnetism, %w{<meter> <meter> <kilogram>}, %w{<second> <second> <ampere>}],
171
- '<oersted>' => [%w{Oe oersted oersteds}, 250.0/Math::PI, :magnetism, %w{<ampere>}, %w{<meter>}],
172
-
173
- #energy
174
- '<joule>' => [%w{J joule Joule joules}, 1, :energy, %w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
175
- '<erg>' => [%w{erg ergs}, Rational(1,1e7), :energy, %w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
176
- '<btu>' => [%w{BTU btu BTUs}, 1055.056, :energy, %w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
177
- '<calorie>' => [%w{cal calorie calories}, 4.18400, :energy,%w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
178
- '<Calorie>' => [%w{Cal Calorie Calories}, 4184.00, :energy,%w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
179
- '<therm-US>' => [%w{th therm therms Therm}, 105480400, :energy,%w{<meter> <meter> <kilogram>}, %w{<second> <second>}],
180
-
181
- #force
182
- '<newton>' => [%w{N Newton newton}, 1, :force, %w{<kilogram> <meter>}, %w{<second> <second>}],
183
- '<dyne>' => [%w{dyn dyne}, Rational(1,1e5), :force, %w{<kilogram> <meter>}, %w{<second> <second>}],
184
- '<pound-force>' => [%w{lbf pound-force}, 4.448222, :force, %w{<kilogram> <meter>}, %w{<second> <second>}],
185
-
186
- #frequency
187
- '<hertz>' => [%w{Hz hertz Hertz}, 1, :frequency, %w{<1>}, %{<second>}],
188
-
189
- #angle
190
- '<radian>' =>[%w{rad radian radian radians}, 1, :angle, %w{<radian>}],
191
- '<degree>' =>[%w{deg degree degrees}, Math::PI / 180.0, :angle, %w{<radian>}],
192
- '<grad>' =>[%w{grad gradian grads}, Math::PI / 200.0, :angle, %w{<radian>}],
193
- '<steradian>' => [%w{sr steradian steradians}, 1, :solid_angle, %w{<steradian>}],
194
-
195
- #rotation
196
- '<rotation>' => [%w{rotation}, 2.0*Math::PI, :angle, %w{<radian>}],
197
- '<rpm>' =>[%w{rpm}, 2.0*Math::PI / 60.0, :angular_velocity, %w{<radian>}, %w{<second>}],
198
-
199
- #memory
200
- '<byte>' =>[%w{B byte}, 1, :memory, %w{<byte>}],
201
- '<bit>' =>[%w{b bit}, 0.125, :memory, %w{<byte>}],
202
-
203
- #currency
204
- '<dollar>'=>[%w{USD dollar}, 1, :currency, %w{<dollar>}],
205
- '<cents>' =>[%w{cents}, Rational(1,100), :currency, %w{<dollar>}],
206
-
207
- #luminosity
208
- '<candela>' => [%w{cd candela}, 1, :luminosity, %w{<candela>}],
209
- '<lumen>' => [%w{lm lumen}, 1, :luminous_power, %w{<candela> <steradian>}],
210
- '<lux>' =>[%w{lux}, 1, :illuminance, %w{<candela> <steradian>}, %w{<meter> <meter>}],
211
-
212
- #power
213
- '<watt>' => [%w{W watt watts}, 1, :power, %w{<kilogram> <meter> <meter>}, %w{<second> <second> <second>}],
214
- '<horsepower>' => [%w{hp horsepower}, 745.699872, :power, %w{<kilogram> <meter> <meter>}, %w{<second> <second> <second>}],
215
-
216
- #radiation
217
- '<gray>' => [%w{Gy gray grays}, 1, :radiation, %w{<meter> <meter>}, %w{<second> <second>}],
218
- '<roentgen>' => [%w{R roentgen}, 0.009330, :radiation, %w{<meter> <meter>}, %w{<second> <second>}],
219
- '<sievert>' => [%w{Sv sievert sieverts}, 1, :radiation, %w{<meter> <meter>}, %w{<second> <second>}],
220
- '<becquerel>' => [%w{Bq bequerel bequerels}, 1, :radiation, %w{<1>},%w{<second>}],
221
- '<curie>' => [%w{Ci curie curies}, 3.7e10, :radiation, %w{<1>},%w{<second>}],
222
-
223
- # rate
224
- '<cpm>' => [%w{cpm}, Rational(1,60), :rate, %w{<count>},%w{<second>}],
225
- '<dpm>' => [%w{dpm}, Rational(1,60), :rate, %w{<count>},%w{<second>}],
226
- '<bpm>' => [%w{bpm}, Rational(1,60), :rate, %w{<count>},%w{<second>}],
227
-
228
- #resolution / typography
229
- '<dot>' => [%w{dot dots}, 1, :resolution, %w{<each>}],
230
- '<pixel>' => [%w{pixel px}, 1, :resolution, %w{<each>}],
231
- '<ppi>' => [%w{ppi}, 1, :resolution, %w{<pixel>}, %w{<inch>}],
232
- '<dpi>' => [%w{dpi}, 1, :typography, %w{<dot>}, %w{<inch>}],
233
- '<pica>' => [%w{pica}, 0.00423333333 , :typography, %w{<meter>}],
234
- '<point>' => [%w{point pt}, 0.000352777778, :typography, %w{<meter>}],
235
-
236
- #other
237
- '<cell>' => [%w{cells cell}, 1, :counting, %w{<each>}],
238
- '<each>' => [%w{each}, 1, :counting, %w{<each>}],
239
- '<count>' => [%w{count}, 1, :counting, %w{<each>}],
240
- '<base-pair>' => [%w{bp}, 1, :counting, %w{<each>}],
241
- '<nucleotide>' => [%w{nt}, 1, :counting, %w{<each>}],
242
- '<molecule>' => [%w{molecule molecules}, 1, :counting, %w{<1>}],
243
- '<dozen>' => [%w{doz dz dozen},12,:prefix_only, %w{<each>}],
244
- '<percent>'=> [%w{% percent}, Rational(1,100), :prefix_only, %w{<1>}],
245
- '<ppm>' => [%w{ppm},Rational(1,1e6),:prefix_only, %w{<1>}],
246
- '<ppt>' => [%w{ppt},Rational(1,1e9),:prefix_only, %w{<1>}],
247
- '<gross>' => [%w{gr gross},144, :prefix_only, %w{<dozen> <dozen>}],
248
- '<decibel>' => [%w{dB decibel decibels}, 1, :logarithmic, %w{<decibel>}]
249
-
250
-
251
- } # doc
252
- end
1
+ require 'ruby_units/unit_definitions/prefix'
2
+ require 'ruby_units/unit_definitions/base'
3
+ require 'ruby_units/unit_definitions/standard'
@@ -0,0 +1,103 @@
1
+ # seed the cache
2
+ Unit('1')
3
+
4
+ Unit.define("meter") do |unit|
5
+ unit.scalar = 1
6
+ unit.numerator = %w{<meter>}
7
+ unit.aliases = %w{m meter meters metre metres}
8
+ unit.kind = :length
9
+ end
10
+
11
+ Unit.define("kilogram") do |unit|
12
+ unit.scalar = 1
13
+ unit.numerator = %w{<kilogram>}
14
+ unit.aliases = %w{kg kilogram kilograms}
15
+ unit.kind = :mass
16
+ end
17
+
18
+ Unit.define("second") do |unit|
19
+ unit.scalar = 1
20
+ unit.numerator = %w{<second>}
21
+ unit.aliases = %w{s sec second seconds}
22
+ unit.kind = :time
23
+ end
24
+
25
+ Unit.define("mole") do |unit|
26
+ unit.scalar = 1
27
+ unit.numerator = %w{<mole>}
28
+ unit.aliases = %w{mol mole}
29
+ unit.kind = :substance
30
+ end
31
+
32
+ Unit.define("ampere") do |unit|
33
+ unit.scalar = 1
34
+ unit.numerator = %w{<ampere>}
35
+ unit.aliases = %w{A ampere amperes amp amps}
36
+ unit.kind = :current
37
+ end
38
+
39
+ Unit.define("radian") do |unit|
40
+ unit.scalar = 1
41
+ unit.numerator = %w{<radian>}
42
+ unit.aliases = %w{rad radian radians}
43
+ unit.kind = :angle
44
+ end
45
+
46
+ Unit.define("kelvin") do |unit|
47
+ unit.scalar = 1
48
+ unit.numerator = %w{<kelvin>}
49
+ unit.aliases = %w{degK kelvin}
50
+ unit.kind = :temperature
51
+ end
52
+
53
+ Unit.define("tempK") do |unit|
54
+ unit.scalar = 1
55
+ unit.numerator = %w{<tempK>}
56
+ unit.aliases = %w{tempK}
57
+ unit.kind = :temperature
58
+ end
59
+
60
+ Unit.define("byte") do |unit|
61
+ unit.scalar = 1
62
+ unit.numerator = %w{<byte>}
63
+ unit.aliases = %w{B byte bytes}
64
+ unit.kind = :memory
65
+ end
66
+
67
+ Unit.define("dollar") do |unit|
68
+ unit.scalar = 1
69
+ unit.numerator = %w{<dollar>}
70
+ unit.aliases = %w{USD dollar}
71
+ unit.kind = :currency
72
+ end
73
+
74
+ Unit.define("candela") do |unit|
75
+ unit.scalar = 1
76
+ unit.numerator = %w{<candela>}
77
+ unit.aliases = %w{cd candela}
78
+ unit.kind = :luminosity
79
+ end
80
+
81
+ Unit.define("each") do |unit|
82
+ unit.scalar = 1
83
+ unit.numerator = %w{<each>}
84
+ unit.aliases = %w{each}
85
+ unit.kind = :counting
86
+ end
87
+
88
+ Unit.define("steradian") do |unit|
89
+ unit.scalar = 1
90
+ unit.numerator = %w{<steradian>}
91
+ unit.aliases = %w{sr steradian steradians}
92
+ unit.kind = :solid_angle
93
+ end
94
+
95
+ Unit.define("decibel") do |unit|
96
+ unit.scalar = 1
97
+ unit.numerator = %w{<decibel>}
98
+ unit.aliases = %w{dB decibel decibels}
99
+ unit.kind = :logarithmic
100
+ end
101
+
102
+
103
+
@@ -0,0 +1,40 @@
1
+
2
+ {
3
+ 'googol' => [%w{googol}, 1e100],
4
+ 'yebi' => [%w{Yi Yebi yebi}, 2**80],
5
+ 'zebi' => [%w{Zi Zebi zebi}, 2**70],
6
+ 'exi' => [%w{Ei Exi exi}, 2**60],
7
+ 'pebi' => [%w{Pi Pebi pebi}, 2**50],
8
+ 'tebi' => [%w{Ti Tebi tebi}, 2**40],
9
+ 'gibi' => [%w{Gi Gibi gibi}, 2**30],
10
+ 'mebi' => [%w{Mi Mebi mebi}, 2**20],
11
+ 'kibi' => [%w{Ki Kibi kibi}, 2**10],
12
+ 'yotta' => [%w{Y Yotta yotta}, 1e24],
13
+ 'zetta' => [%w{Z Zetta zetta}, 1e21],
14
+ 'exa' => [%w{E Exa exa}, 1e18],
15
+ 'peta' => [%w{P Peta peta}, 1e15],
16
+ 'tera' => [%w{T Tera tera}, 1e12],
17
+ 'giga' => [%w{G Giga giga}, 1e9],
18
+ 'mega' => [%w{M Mega mega}, 1e6],
19
+ 'kilo' => [%w{k kilo}, 1e3],
20
+ 'hecto' => [%w{h Hecto hecto}, 1e2],
21
+ 'deca' => [%w{da Deca deca deka}, 1e1],
22
+ '1' => [%w{1}, 1],
23
+ 'deci' => [%w{d Deci deci}, Rational(1,1e1)],
24
+ 'centi' => [%w{c Centi centi}, Rational(1,1e2)],
25
+ 'milli' => [%w{m Milli milli}, Rational(1,1e3)],
26
+ 'micro' => [%w{u Micro micro}, Rational(1,1e6)],
27
+ 'nano' => [%w{n Nano nano}, Rational(1,1e9)],
28
+ 'pico' => [%w{p Pico pico}, Rational(1,1e12)],
29
+ 'femto' => [%w{f Femto femto}, Rational(1,1e15)],
30
+ 'atto' => [%w{a Atto atto}, Rational(1,1e18)],
31
+ 'zepto' => [%w{z Zepto zepto}, Rational(1,1e21)],
32
+ 'yocto' => [%w{y Yocto yocto}, Rational(1,1e24)]
33
+ }.each do |name, definition|
34
+ Unit.define(name) do |unit|
35
+ aliases, scalar = definition
36
+ unit.aliases = aliases
37
+ unit.scalar = scalar
38
+ unit.kind = :prefix
39
+ end
40
+ end
@@ -0,0 +1,705 @@
1
+ # length units
2
+
3
+ Unit.define('inch') do |inch|
4
+ inch.definition = Unit('254/10000 meter')
5
+ inch.aliases = %w{in inch inches "}
6
+ end
7
+
8
+ Unit.define('foot') do |foot|
9
+ foot.definition = Unit('12 inches')
10
+ foot.aliases = %w{ft foot feet '}
11
+ end
12
+
13
+ Unit.define('survey-foot') do |sft|
14
+ sft.definition = Unit('1200/3937 meter')
15
+ sft.aliases = %w{sft sfoot sfeet}
16
+ end
17
+
18
+ Unit.define('yard') do |yard|
19
+ yard.definition = Unit('3 ft')
20
+ yard.aliases = %w{yd yard yards}
21
+ end
22
+
23
+ Unit.define('mile') do |mile|
24
+ mile.definition = Unit('5280 ft')
25
+ mile.aliases = %w{mi mile miles}
26
+ end
27
+
28
+ Unit.define('naut-mile') do |naut|
29
+ naut.definition = Unit('1852 m')
30
+ naut.aliases = %w{nmi M NM}
31
+ end
32
+
33
+ # on land
34
+ Unit.define('league') do |league|
35
+ league.definition = Unit('3 miles')
36
+ league.aliases = %w{league leagues}
37
+ end
38
+
39
+ # at sea
40
+ Unit.define('naut-league') do |naut_league|
41
+ naut_league.definition = Unit('3 nmi')
42
+ naut_league.aliases = %w{nleague nleagues}
43
+ end
44
+
45
+ Unit.define('furlong') do |furlong|
46
+ furlong.definition = Unit('1/8 mile')
47
+ furlong.aliases = %w{fur furlong furlongs}
48
+ end
49
+
50
+ Unit.define('rod') do |rod|
51
+ rod.definition = Unit('33/2 feet')
52
+ rod.aliases = %w{rd rod rods}
53
+ end
54
+
55
+ Unit.define('fathom') do |fathom|
56
+ fathom.definition = Unit('6 ft')
57
+ fathom.aliases = %w{fathom fathoms}
58
+ end
59
+
60
+ Unit.define('mil') do |mil|
61
+ mil.definition = Unit('1/1000 inch')
62
+ mil.aliases = %w{mil mils}
63
+ end
64
+
65
+ Unit.define('angstrom') do |ang|
66
+ ang.definition = Unit('1/10 nm')
67
+ ang.aliases = %w{ang angstrom angstroms}
68
+ end
69
+
70
+ # typesetting
71
+
72
+ Unit.define('point') do |point|
73
+ point.definition = Unit('1/72 ft')
74
+ point.aliases = %w{pt point points}
75
+ end
76
+
77
+ Unit.define('pica') do |pica|
78
+ pica.definition = Unit('12 pt')
79
+ pica.aliases = %w{P pica picas}
80
+ end
81
+
82
+ Unit.define('dot') do |dot|
83
+ dot.definition = Unit('1 each')
84
+ dot.aliases = %w{dot dots}
85
+ dot.kind = :counting
86
+ end
87
+
88
+ Unit.define('pixel') do |pixel|
89
+ pixel.definition = Unit('1 each')
90
+ pixel.aliases = %w{px pixel pixels}
91
+ pixel.kind = :counting
92
+ end
93
+
94
+ Unit.define('ppi') do |ppi|
95
+ ppi.definition = Unit('1 pixel/inch')
96
+ end
97
+
98
+ Unit.define('dpi') do |dpi|
99
+ dpi.definition = Unit('1 dot/inch')
100
+ end
101
+
102
+ # Mass
103
+
104
+ avagadro_constant = Unit('6.02214129e23 1/mol')
105
+
106
+ Unit.define('AMU') do |amu|
107
+ amu.definition = Unit('12 kg/mol') / (12 * avagadro_constant)
108
+ amu.aliases = %w{u AMU amu}
109
+ end
110
+
111
+ Unit.define('dalton') do |dalton|
112
+ dalton.definition = Unit('1 amu')
113
+ dalton.aliases = %w{Da dalton daltons}
114
+ end
115
+
116
+ standard_gravitation = Unit('9.80665 m/s^2')
117
+
118
+ Unit.define('metric-ton') do |mton|
119
+ mton.definition = Unit('1000 kg')
120
+ mton.aliases = %w{tonne}
121
+ end
122
+
123
+ # defined as a rational number to preserve accuracy and minimize round-off errors during
124
+ # calculations
125
+ Unit.define('pound') do |pound|
126
+ pound.definition = Unit(Rational(45359237,1e8), 'kg')
127
+ pound.aliases = %w{lbs lb lbm pound-mass pound pounds #}
128
+ end
129
+
130
+ Unit.define('ounce') do |ounce|
131
+ ounce.definition = Unit('1/16 lbs')
132
+ ounce.aliases = %w{oz ounce ounces}
133
+ end
134
+
135
+ Unit.define('gram') do |gram|
136
+ gram.definition = Unit('1/1000 kg')
137
+ gram.aliases = %w{g gram grams gramme grammes}
138
+ end
139
+
140
+ Unit.define('short-ton') do |ton|
141
+ ton.definition = Unit('2000 lbs')
142
+ ton.aliases = %w{ton tn}
143
+ end
144
+
145
+ Unit.define('carat') do |carat|
146
+ carat.definition = Unit('1/5000 kg')
147
+ carat.aliases = %w{ct carat carats}
148
+ end
149
+
150
+ # time
151
+
152
+ Unit.define('minute') do |min|
153
+ min.definition = Unit('60 seconds')
154
+ min.aliases = %w{min minute minutes}
155
+ end
156
+
157
+ Unit.define('hour') do |hour|
158
+ hour.definition = Unit('60 minutes')
159
+ hour.aliases = %w{h hr hrs hour hours}
160
+ end
161
+
162
+ Unit.define('day') do |day|
163
+ day.definition = Unit('24 hours')
164
+ day.aliases = %w{d day days}
165
+ end
166
+
167
+ Unit.define('week') do |week|
168
+ week.definition = Unit('7 days')
169
+ week.aliases = %w{wk week weeks}
170
+ end
171
+
172
+ Unit.define('fortnight') do |fortnight|
173
+ fortnight.definition = Unit('2 weeks')
174
+ fortnight.aliases = %w{fortnight fortnights}
175
+ end
176
+
177
+ Unit.define('year') do |year|
178
+ year.definition = Unit('31556926 seconds') # works out to 365.24219907407405 days
179
+ year.aliases = %w{y yr year years annum}
180
+ end
181
+
182
+ Unit.define('decade') do |decade|
183
+ decade.definition = Unit('10 years')
184
+ decade.aliases = %w{decade decades}
185
+ end
186
+
187
+ Unit.define('century') do |century|
188
+ century.definition = Unit('100 years')
189
+ century.aliases = %w{century centuries}
190
+ end
191
+
192
+ # area
193
+
194
+ Unit.define('hectare') do |hectare|
195
+ hectare.definition = Unit('10000 m^2')
196
+ end
197
+
198
+ Unit.define('acre') do |acre|
199
+ acre.definition = Unit('1 mi')**2 / 640
200
+ acre.aliases = %w{acre acres}
201
+ end
202
+
203
+ Unit.define('sqft') do |sqft|
204
+ sqft.definition = Unit('1 ft^2')
205
+ end
206
+
207
+ Unit.define('sqin') do |sqin|
208
+ sqin.definition = Unit('1 in^2')
209
+ end
210
+
211
+ # volume
212
+
213
+ Unit.define('liter') do |liter|
214
+ liter.definition = Unit('1/1000 m^3')
215
+ liter.aliases = %w{l L liter liters litre litres}
216
+ end
217
+
218
+ Unit.define('gallon') do |gallon|
219
+ gallon.definition = Unit('231 in^3')
220
+ gallon.aliases = %w{gal gallon gallons}
221
+ end
222
+
223
+ Unit.define('quart') do |quart|
224
+ quart.definition = Unit('1/4 gal')
225
+ quart.aliases = %w{qt quart quarts}
226
+ end
227
+
228
+ Unit.define('pint') do |pint|
229
+ pint.definition = Unit('1/8 gal')
230
+ pint.aliases = %w{pt pint pints}
231
+ end
232
+
233
+ Unit.define('cup') do |cup|
234
+ cup.definition = Unit('1/16 gal')
235
+ cup.aliases = %w{cu cup cups}
236
+ end
237
+
238
+ Unit.define('fluid-ounce') do |floz|
239
+ floz.definition = Unit('1/128 gal')
240
+ floz.aliases = %w{floz fluid-ounce}
241
+ end
242
+
243
+ Unit.define('tablespoon') do |tbsp|
244
+ tbsp.definition = Unit('1/2 floz')
245
+ tbsp.aliases = %w{tbs tbsp tablespoon tablespoons}
246
+ end
247
+
248
+ Unit.define('teaspoon') do |tsp|
249
+ tsp.definition = Unit('1/3 tablespoon')
250
+ tsp.aliases = %w{tsp teaspoon teaspoons}
251
+ end
252
+
253
+ # volumetric flow
254
+
255
+ Unit.define('cfm') do |cfm|
256
+ cfm.definition = Unit('1 ft^3/minute')
257
+ cfm.aliases = %w{cfm CFM CFPM}
258
+ end
259
+
260
+ # speed
261
+
262
+ Unit.define('kph') do |kph|
263
+ kph.definition = Unit('1 kilometer/hour')
264
+ end
265
+
266
+ Unit.define('mph') do |mph|
267
+ mph.definition = Unit('1 mile/hour')
268
+ end
269
+
270
+ Unit.define('fps') do |fps|
271
+ fps.definition = Unit('1 foot/second')
272
+ end
273
+
274
+ Unit.define('knot') do |knot|
275
+ knot.definition = Unit('1 nmi/hour')
276
+ knot.aliases = %w{kt kn kts knot knots}
277
+ end
278
+
279
+ Unit.define('gee') do |gee|
280
+ # approximated as a rational number to minimize round-off errors
281
+ gee.definition = Unit(Rational(196131,20000), 'm/s^2') # equivalent to 9.80655 m/s^2
282
+ gee.aliases = %w{gee standard-gravitation}
283
+ end
284
+
285
+ # temperature differences
286
+
287
+ Unit.define('newton') do |newton|
288
+ newton.definition = Unit('1 kg*m/s^2')
289
+ newton.aliases = %w{N newton newtons}
290
+ end
291
+
292
+ Unit.define('dyne') do |dyne|
293
+ dyne.definition = Unit('1/100000 N')
294
+ dyne.aliases = %w{dyn dyne}
295
+ end
296
+
297
+ Unit.define('pound-force') do |lbf|
298
+ lbf.definition = Unit('1 lb') * Unit('1 gee')
299
+ lbf.aliases = %w{lbf pound-force}
300
+ end
301
+
302
+ Unit.define('poundal') do |poundal|
303
+ poundal.definition = Unit('1 lb') * Unit('1 ft/s^2')
304
+ poundal.aliases = %w{pdl poundal poundals}
305
+ end
306
+
307
+ temp_convert_factor = Rational(2501999792983609,4503599627370496) # approximates 1/1.8
308
+
309
+ Unit.define('celsius') do |celsius|
310
+ celsius.definition = Unit('1 degK')
311
+ celsius.aliases = %w{degC celsius centigrade}
312
+ end
313
+
314
+ Unit.define('fahrenheit') do |fahrenheit|
315
+ fahrenheit.definition = Unit(temp_convert_factor, 'degK')
316
+ fahrenheit.aliases = %w{degF fahrenheit}
317
+ end
318
+
319
+ Unit.define('rankine') do |rankine|
320
+ rankine.definition = Unit('1 degF')
321
+ rankine.aliases = %w{degR rankine}
322
+ end
323
+
324
+ Unit.define('tempC') do |tempC|
325
+ tempC.definition = Unit('1 tempK')
326
+ end
327
+
328
+ Unit.define('tempF') do |tempF|
329
+ tempF.definition = Unit(temp_convert_factor, 'tempK')
330
+ end
331
+
332
+ Unit.define('tempR') do |tempR|
333
+ tempR.definition = Unit('1 tempF')
334
+ end
335
+
336
+ # astronomy
337
+
338
+ speed_of_light = Unit('299792458 m/s')
339
+
340
+ Unit.define('light-second') do |ls|
341
+ ls.definition = Unit('1 s') * speed_of_light
342
+ ls.aliases = %w{ls lsec light-second}
343
+ end
344
+
345
+ Unit.define('light-minute') do |lmin|
346
+ lmin.definition = Unit('1 min') * speed_of_light
347
+ lmin.aliases = %w{lmin light-minute}
348
+ end
349
+
350
+ Unit.define('light-year') do |ly|
351
+ ly.definition = Unit('1 y') * speed_of_light
352
+ ly.aliases = %w{ly light-year}
353
+ end
354
+
355
+ Unit.define('parsec') do |parsec|
356
+ parsec.definition = Unit('3.26163626 ly')
357
+ parsec.aliases = %w{pc parsec parsecs}
358
+ end
359
+
360
+ # once was '149597900000 m' but there appears to be a more accurate estimate according to wikipedia
361
+ # see http://en.wikipedia.org/wiki/Astronomical_unit
362
+ Unit.define('AU') do |au|
363
+ au.definition = Unit('149597870700 m')
364
+ au.aliases = %w{AU astronomical-unit}
365
+ end
366
+
367
+ Unit.define('redshift') do |red|
368
+ red.definition = Unit('1.302773e26 m')
369
+ red.aliases = %w{z red-shift}
370
+ end
371
+
372
+ # mass
373
+
374
+ Unit.define('slug') do |slug|
375
+ slug.definition = Unit('1 lbf*s^2/ft')
376
+ slug.aliases = %w{slug slugs}
377
+ end
378
+
379
+ # pressure
380
+
381
+ Unit.define('pascal') do |pascal|
382
+ pascal.definition = Unit('1 kg/m*s^2')
383
+ pascal.aliases = %w{Pa pascal pascals}
384
+ end
385
+
386
+ Unit.define('bar') do |bar|
387
+ bar.definition = Unit('100 kPa')
388
+ bar.aliases = %w{bar bars}
389
+ end
390
+
391
+ Unit.define('atm') do |atm|
392
+ atm.definition = Unit('101325 Pa')
393
+ atm.aliases = %w{atm ATM atmosphere atmospheres}
394
+ end
395
+
396
+ Unit.define('mmHg') do |mmhg|
397
+ density_of_mercury = Unit('7653360911758079/562949953421312 g/cm^3') # 13.5951 g/cm^3 at 0 tempC
398
+ mmhg.definition = Unit('1 mm') * Unit('1 gee') * density_of_mercury
399
+ end
400
+
401
+ Unit.define('inHg') do |inhg|
402
+ density_of_mercury = Unit('7653360911758079/562949953421312 g/cm^3') # 13.5951 g/cm^3 at 0 tempC
403
+ inhg.definition = Unit('1 in') * Unit('1 gee') * density_of_mercury
404
+ end
405
+
406
+ Unit.define('torr') do |torr|
407
+ torr.definition = Unit('1/760 atm')
408
+ torr.aliases = %w{Torr torr}
409
+ end
410
+
411
+ Unit.define('psi') do |psi|
412
+ psi.definition = Unit('1 lbf/in^2')
413
+ end
414
+
415
+ Unit.define('cmh2o') do |cmh2o|
416
+ density_of_water = Unit('1 g/cm^3') # at 4 tempC
417
+ cmh2o.definition = Unit('1 cm') * Unit('1 gee') * density_of_water
418
+ cmh2o.aliases = %w{cmH2O cmh2o cmAq}
419
+ end
420
+
421
+ Unit.define('inh2o') do |inh2o|
422
+ density_of_water = Unit('1 g/cm^3') # at 4 tempC
423
+ inh2o.definition = Unit('1 in') * Unit('1 gee') * density_of_water
424
+ inh2o.aliases = %w{inH2O inh2o inAq}
425
+ end
426
+
427
+ #viscosity
428
+
429
+ Unit.define('poise') do |poise|
430
+ poise.definition = Unit('dPa*s')
431
+ poise.aliases = %w{P poise}
432
+ end
433
+
434
+ Unit.define('stokes') do |stokes|
435
+ stokes.definition = Unit('1 cm^2/s')
436
+ stokes.aliases = %w{St stokes}
437
+ end
438
+
439
+ # #energy
440
+
441
+ Unit.define('joule') do |joule|
442
+ joule.definition = Unit('1 N*m')
443
+ joule.aliases = %w{J joule joules}
444
+ end
445
+
446
+ Unit.define('erg') do |erg|
447
+ erg.definition = Unit('1 g*cm^2/s^2')
448
+ erg.aliases = %w{erg ergs}
449
+ end
450
+
451
+ #power
452
+
453
+ Unit.define('watt') do |watt|
454
+ watt.definition = Unit('1 N*m/s')
455
+ watt.aliases = %w{W Watt watt watts}
456
+ end
457
+
458
+ Unit.define('horsepower') do |hp|
459
+ hp.definition = Unit('33000 ft*lbf/min')
460
+ hp.aliases = %w{hp horsepower}
461
+ end
462
+
463
+ # energy
464
+ Unit.define('btu') do |btu|
465
+ btu.definition = Unit('2320092679909671/2199023255552 J') # 1055.056 J --- ISO standard
466
+ btu.aliases = %w{Btu btu Btus btus}
467
+ end
468
+
469
+ Unit.define('therm') do |therm|
470
+ therm.definition = Unit('100 kBtu')
471
+ therm.aliases = %w{thm therm therms Therm}
472
+ end
473
+
474
+ # "small" calorie
475
+ Unit.define('calorie') do |calorie|
476
+ calorie.definition = Unit('4.184 J')
477
+ calorie.aliases = %w{cal calorie calories}
478
+ end
479
+
480
+ # "big" calorie
481
+ Unit.define('Calorie') do |calorie|
482
+ calorie.definition = Unit('1 kcal')
483
+ calorie.aliases = %w{Cal Calorie Calories}
484
+ end
485
+
486
+ Unit.define('molar') do |molar|
487
+ molar.definition = Unit('1 mole/l')
488
+ molar.aliases = %w{M molar}
489
+ end
490
+
491
+ # potential
492
+ Unit.define('volt') do |volt|
493
+ volt.definition = Unit('1 W/A')
494
+ volt.aliases = %w{V volt volts}
495
+ end
496
+
497
+ # capacitance
498
+ Unit.define('farad') do |farad|
499
+ farad.definition = Unit('1 A*s/V')
500
+ farad.aliases = %w{F farad farads}
501
+ end
502
+
503
+ # charge
504
+ Unit.define('coulomb') do |coulomb|
505
+ coulomb.definition = Unit('1 A*s')
506
+ coulomb.aliases = %w{C coulomb coulombs}
507
+ end
508
+
509
+ # conductance
510
+ Unit.define('siemens') do |siemens|
511
+ siemens.definition = Unit('1 A/V')
512
+ siemens.aliases = %w{S siemens}
513
+ end
514
+
515
+ # inductance
516
+ Unit.define('henry') do |henry|
517
+ henry.definition = Unit('1 J/A^2')
518
+ henry.aliases = %w{H henry henries}
519
+ end
520
+
521
+ # resistance
522
+ Unit.define('ohm') do |ohm|
523
+ ohm.definition = Unit('1 V/A')
524
+ ohm.aliases = %w{Ohm ohm ohms}
525
+ end
526
+
527
+ # magnetism
528
+
529
+ Unit.define('weber') do |weber|
530
+ weber.definition = Unit('1 V*s')
531
+ weber.aliases = %w{Wb weber webers}
532
+ end
533
+
534
+ Unit.define('tesla') do |tesla|
535
+ tesla.definition = Unit('1 V*s/m^2')
536
+ tesla.aliases = %w{T tesla teslas}
537
+ end
538
+
539
+ Unit.define('gauss') do |gauss|
540
+ gauss.definition = Unit('100 microT')
541
+ gauss.aliases = %w{G gauss}
542
+ end
543
+
544
+ Unit.define('maxwell') do |maxwell|
545
+ maxwell.definition = Unit('1 gauss*cm^2')
546
+ maxwell.aliases = %w{Mx maxwell maxwells}
547
+ end
548
+
549
+ Unit.define('oersted') do |oersted|
550
+ oersted.definition = Unit(250.0/Math::PI, 'A/m')
551
+ oersted.aliases = %w{Oe oersted oersteds}
552
+ end
553
+
554
+ #activity
555
+ Unit.define('katal') do |katal|
556
+ katal.definition = Unit('1 mole/sec')
557
+ katal.aliases = %w{kat katal}
558
+ end
559
+
560
+ Unit.define('unit') do |unit|
561
+ unit.definition = Unit('1/60 microkatal')
562
+ unit.aliases = %w{U enzUnit}
563
+ end
564
+
565
+ #frequency
566
+
567
+ Unit.define('hertz') do |hz|
568
+ hz.definition = Unit('1 1/s')
569
+ hz.aliases = %w{Hz hertz}
570
+ end
571
+
572
+ #angle
573
+ Unit.define('degree') do |deg|
574
+ deg.definition = Unit(Math::PI / 180.0, 'radian')
575
+ deg.aliases = %w{deg degree degrees}
576
+ end
577
+
578
+ Unit.define('grad') do |grad|
579
+ grad.definition = Unit(Math::PI / 200.0, 'radian')
580
+ grad.aliases = %w{grad gradian grads}
581
+ end
582
+
583
+ #rotation
584
+ Unit.define('rotation') do |rotation|
585
+ rotation.definition = Unit(2.0*Math::PI, 'radian')
586
+ end
587
+
588
+ Unit.define('rpm') do |rpm|
589
+ rpm.definition = Unit('1 rotation/min')
590
+ end
591
+
592
+ #memory
593
+ Unit.define('bit') do |bit|
594
+ bit.definition = Unit('1/8 byte')
595
+ bit.aliases = %w{b bit}
596
+ end
597
+
598
+ #currency
599
+ Unit.define('cents') do |cents|
600
+ cents.definition = Unit('1/100 dollar')
601
+ end
602
+
603
+ #luminosity
604
+ Unit.define('lumen') do |lumen|
605
+ lumen.definition = Unit('1 cd*steradian')
606
+ lumen.aliases = %w{lm lumen}
607
+ end
608
+
609
+ Unit.define('lux') do |lux|
610
+ lux.definition = Unit('1 lumen/m^2')
611
+ end
612
+
613
+ #radiation
614
+ Unit.define('gray') do |gray|
615
+ gray.definition = Unit('1 J/kg')
616
+ gray.aliases = %w{Gy gray grays}
617
+ end
618
+
619
+ Unit.define('roentgen') do |roentgen|
620
+ roentgen.definition = Unit('2.58e-4 C/kg')
621
+ roentgen.aliases = %w{R roentgen}
622
+ end
623
+
624
+ Unit.define('sievert') do |sievert|
625
+ sievert.definition = Unit('1 J/kg')
626
+ sievert.aliases = %w{Sv sievert sieverts}
627
+ end
628
+
629
+ Unit.define('becquerel') do |becquerel|
630
+ becquerel.definition = Unit('1 1/s')
631
+ becquerel.aliases = %w{Bq becquerel becquerels}
632
+ end
633
+
634
+ Unit.define('curie') do |curie|
635
+ curie.definition = Unit('37 GBq')
636
+ curie.aliases = %w{Ci curie curies}
637
+ end
638
+
639
+ Unit.define('count') do |count|
640
+ count.definition = Unit('1 each')
641
+ count.kind = :counting
642
+ end
643
+
644
+ # rate
645
+ Unit.define('cpm') do |cpm|
646
+ cpm.definition = Unit('1 count/min')
647
+ end
648
+
649
+ Unit.define('dpm') do |dpm|
650
+ dpm.definition = Unit('1 count/min')
651
+ end
652
+
653
+ Unit.define('bpm') do |bpm|
654
+ bpm.definition = Unit('1 count/min')
655
+ end
656
+
657
+ # misc
658
+ Unit.define('dozen') do |dozen|
659
+ dozen.definition = Unit('12 each')
660
+ dozen.aliases = %w{doz dz dozen}
661
+ dozen.kind = :counting
662
+ end
663
+
664
+ Unit.define('gross') do |gross|
665
+ gross.definition = Unit('12 dozen')
666
+ gross.aliases = %w{gr gross}
667
+ gross.kind = :counting
668
+ end
669
+
670
+ Unit.define('cell') do |cell|
671
+ cell.definition = Unit('1 each')
672
+ cell.aliases = %w{cells cell}
673
+ cell.kind = :counting
674
+ end
675
+
676
+ Unit.define('base-pair') do |bp|
677
+ bp.definition = Unit('1 each')
678
+ bp.aliases = %w{bp base-pair}
679
+ bp.kind = :counting
680
+ end
681
+
682
+ Unit.define('nucleotide') do |nt|
683
+ nt.definition = Unit('1 each')
684
+ nt.aliases = %w{nt}
685
+ nt.kind = :counting
686
+ end
687
+
688
+ Unit.define('molecule') do |molecule|
689
+ molecule.definition = Unit('1 each')
690
+ molecule.aliases = %w{molecule molecules}
691
+ molecule.kind = :counting
692
+ end
693
+
694
+ Unit.define('percent') do |percent|
695
+ percent.definition = Unit('1/100')
696
+ percent.aliases = %w{% percent}
697
+ end
698
+
699
+ Unit.define('ppm') do |ppm|
700
+ ppm.definition = Unit(1) / 1_000_000
701
+ end
702
+
703
+ Unit.define('ppb') do |ppb|
704
+ ppb.definition = Unit(1) / 1_000_000_000
705
+ end