unitwise 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -2
- data/data/derived_unit.yaml +156 -8
- data/lib/unitwise/atom.rb +1 -1
- data/lib/unitwise/functional.rb +2 -2
- data/lib/unitwise/measurement.rb +2 -2
- data/lib/unitwise/scale.rb +2 -2
- data/lib/unitwise/term.rb +2 -2
- data/lib/unitwise/unit.rb +2 -2
- data/lib/unitwise/version.rb +1 -1
- data/test/unitwise/measurement_test.rb +7 -0
- metadata +2 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7b43a98361a2647155beb5a86d6bc1281e8f160c
|
4
|
+
data.tar.gz: 25dbd408ecc497a0003592c17c41b3636537d2bb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e1b4d53bc2c1cbe081df9a5df31d82872ae390773831558137fba10139d27fb9e4fab531149f5f876a5c4a7bf57d97340ef70e671d0fbabaa5c930a953f96a1
|
7
|
+
data.tar.gz: f17f89d11af392f7c9b520ad4defe197ddf9657ccb7bce721923f59a229caf5336ab892653c01fc9f6d5d546864bca1b7c298cd5e56ccb54e480e80fcc90bc8e
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Unitwise
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/unitwise.png)](http://badge.fury.io/rb/unitwise)
|
3
4
|
[![Build Status](https://travis-ci.org/joshwlewis/unitwise.png)](https://travis-ci.org/joshwlewis/unitwise)
|
4
5
|
[![Dependency Status](https://gemnasium.com/joshwlewis/unitwise.png)](https://gemnasium.com/joshwlewis/unitwise)
|
5
6
|
[![Coverage Status](https://coveralls.io/repos/joshwlewis/unitwise/badge.png)](https://coveralls.io/r/joshwlewis/unitwise)
|
@@ -10,8 +11,6 @@ Unitwise is a library for performing mathematical operations and conversions on
|
|
10
11
|
|
11
12
|
Unitwise supports a vast number of units. At the time of writing, it supports 95 metric units, 199 non-metric units, and 24 unit prefixes. That's approximately 2,500 basic units, but these can also be combined through multiplication and/or division to create an infinite number of possibilities.
|
12
13
|
|
13
|
-
Please note that while Unitwise is functional, it is still under development.
|
14
|
-
|
15
14
|
## Usage
|
16
15
|
|
17
16
|
### Initialization:
|
data/data/derived_unit.yaml
CHANGED
@@ -630,7 +630,7 @@
|
|
630
630
|
:primary_code: AU
|
631
631
|
:secondary_code: ASU
|
632
632
|
:scale:
|
633
|
-
:value: 149597.
|
633
|
+
:value: 149597.870691
|
634
634
|
:unit_code: Mm
|
635
635
|
:classification: iso1000
|
636
636
|
:property: length
|
@@ -688,7 +688,7 @@
|
|
688
688
|
- :names: permittivity of vacuum
|
689
689
|
:symbol: <i>ε<sub><r>0</r></sub></i>
|
690
690
|
:primary_code: '[eps_0]'
|
691
|
-
:secondary_code: '[
|
691
|
+
:secondary_code: '[EPS_0]'
|
692
692
|
:scale:
|
693
693
|
:value: 8.854187817e-12
|
694
694
|
:unit_code: F/m
|
@@ -700,7 +700,7 @@
|
|
700
700
|
- :names: permeability of vacuum
|
701
701
|
:symbol: <i>μ<sub><r>0</r></sub></i>
|
702
702
|
:primary_code: '[mu_0]'
|
703
|
-
:secondary_code: '[
|
703
|
+
:secondary_code: '[MU_0]'
|
704
704
|
:scale:
|
705
705
|
:value: 1.0
|
706
706
|
:unit_code: 4.[pi].10*-7.N/A2
|
@@ -1754,6 +1754,51 @@
|
|
1754
1754
|
:metric: false
|
1755
1755
|
:special: false
|
1756
1756
|
:arbitrary: false
|
1757
|
+
- :names: metric fluid ounce
|
1758
|
+
:symbol: oz fl
|
1759
|
+
:primary_code: '[foz_m]'
|
1760
|
+
:secondary_code: '[FOZ_M]'
|
1761
|
+
:scale:
|
1762
|
+
:value: 30.0
|
1763
|
+
:unit_code: mL
|
1764
|
+
:classification: us-volumes
|
1765
|
+
:property: fluid volume
|
1766
|
+
:metric: false
|
1767
|
+
:special: false
|
1768
|
+
:arbitrary: false
|
1769
|
+
- :names: metric cup
|
1770
|
+
:primary_code: '[cup_m]'
|
1771
|
+
:secondary_code: '[CUP_M]'
|
1772
|
+
:scale:
|
1773
|
+
:value: 240.0
|
1774
|
+
:unit_code: mL
|
1775
|
+
:classification: us-volumes
|
1776
|
+
:property: volume
|
1777
|
+
:metric: false
|
1778
|
+
:special: false
|
1779
|
+
:arbitrary: false
|
1780
|
+
- :names: metric teaspoon
|
1781
|
+
:primary_code: '[tsp_m]'
|
1782
|
+
:secondary_code: '[TSP_M]'
|
1783
|
+
:scale:
|
1784
|
+
:value: 5.0
|
1785
|
+
:unit_code: mL
|
1786
|
+
:classification: us-volumes
|
1787
|
+
:property: volume
|
1788
|
+
:metric: false
|
1789
|
+
:special: false
|
1790
|
+
:arbitrary: false
|
1791
|
+
- :names: metric tablespoon
|
1792
|
+
:primary_code: '[tbs_m]'
|
1793
|
+
:secondary_code: '[TBS_M]'
|
1794
|
+
:scale:
|
1795
|
+
:value: 15.0
|
1796
|
+
:unit_code: mL
|
1797
|
+
:classification: us-volumes
|
1798
|
+
:property: volume
|
1799
|
+
:metric: false
|
1800
|
+
:special: false
|
1801
|
+
:arbitrary: false
|
1757
1802
|
- :names: gallon
|
1758
1803
|
:primary_code: '[gal_br]'
|
1759
1804
|
:secondary_code: '[GAL_BR]'
|
@@ -2043,6 +2088,17 @@
|
|
2043
2088
|
:metric: false
|
2044
2089
|
:special: false
|
2045
2090
|
:arbitrary: false
|
2091
|
+
- :names: metric ounce
|
2092
|
+
:primary_code: '[oz_m]'
|
2093
|
+
:secondary_code: '[OZ_M]'
|
2094
|
+
:scale:
|
2095
|
+
:value: 28.0
|
2096
|
+
:unit_code: g
|
2097
|
+
:classification: apoth
|
2098
|
+
:property: mass
|
2099
|
+
:metric: false
|
2100
|
+
:special: false
|
2101
|
+
:arbitrary: false
|
2046
2102
|
- :names: line
|
2047
2103
|
:primary_code: '[lne]'
|
2048
2104
|
:secondary_code: '[LNE]'
|
@@ -2176,6 +2232,18 @@
|
|
2176
2232
|
:metric: false
|
2177
2233
|
:special: true
|
2178
2234
|
:arbitrary: false
|
2235
|
+
- :names: degree Rankine
|
2236
|
+
:symbol: °R
|
2237
|
+
:primary_code: '[degR]'
|
2238
|
+
:secondary_code: '[degR]'
|
2239
|
+
:scale:
|
2240
|
+
:value: 5.0
|
2241
|
+
:unit_code: K/9
|
2242
|
+
:classification: heat
|
2243
|
+
:property: temperature
|
2244
|
+
:metric: false
|
2245
|
+
:special: false
|
2246
|
+
:arbitrary: false
|
2179
2247
|
- :names: calorie at 15 °C
|
2180
2248
|
:symbol: cal<sub>15°C</sub>
|
2181
2249
|
:primary_code: cal_[15]
|
@@ -2355,6 +2423,30 @@
|
|
2355
2423
|
:metric: false
|
2356
2424
|
:special: false
|
2357
2425
|
:arbitrary: false
|
2426
|
+
- :names: tex
|
2427
|
+
:symbol: tex
|
2428
|
+
:primary_code: tex
|
2429
|
+
:secondary_code: TEX
|
2430
|
+
:scale:
|
2431
|
+
:value: 1.0
|
2432
|
+
:unit_code: g/km
|
2433
|
+
:classification: heat
|
2434
|
+
:property: linear mass density (of textile thread)
|
2435
|
+
:metric: true
|
2436
|
+
:special: false
|
2437
|
+
:arbitrary: false
|
2438
|
+
- :names: Denier
|
2439
|
+
:symbol: den
|
2440
|
+
:primary_code: '[den]'
|
2441
|
+
:secondary_code: '[DEN]'
|
2442
|
+
:scale:
|
2443
|
+
:value: 1.0
|
2444
|
+
:unit_code: g/9/km
|
2445
|
+
:classification: heat
|
2446
|
+
:property: linear mass density (of textile thread)
|
2447
|
+
:metric: false
|
2448
|
+
:special: false
|
2449
|
+
:arbitrary: false
|
2358
2450
|
- :names: meter of water column
|
2359
2451
|
:symbol: m H<sub><r>2</r></sub>O
|
2360
2452
|
:primary_code: m[H2O]
|
@@ -2394,7 +2486,7 @@
|
|
2394
2486
|
- :names: inch of mercury column
|
2395
2487
|
:symbol: in Hg
|
2396
2488
|
:primary_code: '[in_i''Hg]'
|
2397
|
-
:secondary_code: '[
|
2489
|
+
:secondary_code: '[IN_I''HG]'
|
2398
2490
|
:scale:
|
2399
2491
|
:value: 1.0
|
2400
2492
|
:unit_code: m[Hg].[in_i]/m
|
@@ -2484,7 +2576,7 @@
|
|
2484
2576
|
:secondary_code: '[CH]'
|
2485
2577
|
:scale:
|
2486
2578
|
:value: 1.0
|
2487
|
-
:unit_code: mm/
|
2579
|
+
:unit_code: mm/3
|
2488
2580
|
:classification: clinical
|
2489
2581
|
:property: gauge of catheters
|
2490
2582
|
:metric: false
|
@@ -2496,7 +2588,7 @@
|
|
2496
2588
|
:secondary_code: '[DRP]'
|
2497
2589
|
:scale:
|
2498
2590
|
:value: 1.0
|
2499
|
-
:unit_code: ml/
|
2591
|
+
:unit_code: ml/20
|
2500
2592
|
:classification: clinical
|
2501
2593
|
:property: volume
|
2502
2594
|
:metric: false
|
@@ -2875,6 +2967,17 @@
|
|
2875
2967
|
:metric: false
|
2876
2968
|
:special: false
|
2877
2969
|
:arbitrary: true
|
2970
|
+
- :names: anti factor Xa unit
|
2971
|
+
:primary_code: '[anti''Xa''U]'
|
2972
|
+
:secondary_code: '[ANTI''XA''U]'
|
2973
|
+
:scale:
|
2974
|
+
:value: 1.0
|
2975
|
+
:unit_code: '1'
|
2976
|
+
:classification: chemical
|
2977
|
+
:property: biologic activity of factor Xa inhibitor (heparin)
|
2978
|
+
:metric: false
|
2979
|
+
:special: false
|
2980
|
+
:arbitrary: true
|
2878
2981
|
- :names: Todd unit
|
2879
2982
|
:primary_code: '[todd''U]'
|
2880
2983
|
:secondary_code: '[TODD''U]'
|
@@ -2987,6 +3090,18 @@
|
|
2987
3090
|
:metric: false
|
2988
3091
|
:special: false
|
2989
3092
|
:arbitrary: true
|
3093
|
+
- :names: 50% embryo infectious dose
|
3094
|
+
:symbol: EID<sub>50</sub>
|
3095
|
+
:primary_code: '[EID_50]'
|
3096
|
+
:secondary_code: '[EID_50]'
|
3097
|
+
:scale:
|
3098
|
+
:value: 1.0
|
3099
|
+
:unit_code: '1'
|
3100
|
+
:classification: chemical
|
3101
|
+
:property: biologic activity (infectivity) of an infectious agent preparation
|
3102
|
+
:metric: false
|
3103
|
+
:special: false
|
3104
|
+
:arbitrary: true
|
2990
3105
|
- :names: plaque forming units
|
2991
3106
|
:symbol: PFU
|
2992
3107
|
:primary_code: '[PFU]'
|
@@ -3091,7 +3206,40 @@
|
|
3091
3206
|
:value: 1.0
|
3092
3207
|
:unit_code: '1'
|
3093
3208
|
:classification: chemical
|
3094
|
-
:property: procedure defined amount of
|
3209
|
+
:property: procedure defined amount of a poliomyelitis d-antigen substance
|
3210
|
+
:metric: false
|
3211
|
+
:special: false
|
3212
|
+
:arbitrary: true
|
3213
|
+
- :names: fibrinogen equivalent unit
|
3214
|
+
:primary_code: '[FEU]'
|
3215
|
+
:secondary_code: '[FEU]'
|
3216
|
+
:scale:
|
3217
|
+
:value: 1.0
|
3218
|
+
:unit_code: '1'
|
3219
|
+
:classification: chemical
|
3220
|
+
:property: amount of fibrinogen broken down into the measured d-dimers
|
3221
|
+
:metric: false
|
3222
|
+
:special: false
|
3223
|
+
:arbitrary: true
|
3224
|
+
- :names: ELISA unit
|
3225
|
+
:primary_code: '[ELU]'
|
3226
|
+
:secondary_code: '[ELU]'
|
3227
|
+
:scale:
|
3228
|
+
:value: 1.0
|
3229
|
+
:unit_code: '1'
|
3230
|
+
:classification: chemical
|
3231
|
+
:property: arbitrary ELISA unit
|
3232
|
+
:metric: false
|
3233
|
+
:special: false
|
3234
|
+
:arbitrary: true
|
3235
|
+
- :names: Ehrlich unit
|
3236
|
+
:primary_code: '[EU]'
|
3237
|
+
:secondary_code: '[EU]'
|
3238
|
+
:scale:
|
3239
|
+
:value: 1.0
|
3240
|
+
:unit_code: '1'
|
3241
|
+
:classification: chemical
|
3242
|
+
:property: Ehrlich unit
|
3095
3243
|
:metric: false
|
3096
3244
|
:special: false
|
3097
3245
|
:arbitrary: true
|
@@ -3383,7 +3531,7 @@
|
|
3383
3531
|
- :names: baud
|
3384
3532
|
:symbol: Bd
|
3385
3533
|
:primary_code: Bd
|
3386
|
-
:secondary_code:
|
3534
|
+
:secondary_code: BD
|
3387
3535
|
:scale:
|
3388
3536
|
:value: 1.0
|
3389
3537
|
:unit_code: /s
|
data/lib/unitwise/atom.rb
CHANGED
data/lib/unitwise/functional.rb
CHANGED
@@ -9,11 +9,11 @@ module Unitwise
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def scalar
|
12
|
-
puts "Warning: Mathematical operations with special units
|
12
|
+
puts "Warning: Mathematical operations with special units not reccomended by UCUM."
|
13
13
|
super()
|
14
14
|
end
|
15
15
|
|
16
|
-
def functional(x, direction=1)
|
16
|
+
def functional(x=scalar, direction=1)
|
17
17
|
function.functional(x, direction)
|
18
18
|
end
|
19
19
|
|
data/lib/unitwise/measurement.rb
CHANGED
@@ -53,11 +53,11 @@ module Unitwise
|
|
53
53
|
if other_unit.special?
|
54
54
|
other_unit.functional functional(value, -1)
|
55
55
|
else
|
56
|
-
functional(value, -1)
|
56
|
+
functional(value, -1) / other_unit.scalar
|
57
57
|
end
|
58
58
|
else
|
59
59
|
if other_unit.special?
|
60
|
-
other_unit.functional(
|
60
|
+
other_unit.functional(scalar)
|
61
61
|
else
|
62
62
|
scalar / other_unit.scalar
|
63
63
|
end
|
data/lib/unitwise/scale.rb
CHANGED
data/lib/unitwise/term.rb
CHANGED
@@ -53,8 +53,8 @@ module Unitwise
|
|
53
53
|
(factor * (prefix ? prefix.scalar : 1) * (atom ? atom.scalar : 1)) ** exponent
|
54
54
|
end
|
55
55
|
|
56
|
-
def functional(
|
57
|
-
(factor * (prefix ? prefix.scalar : 1)) * (atom ? atom.functional(
|
56
|
+
def functional(x=scalar, direction=1)
|
57
|
+
(factor * (prefix ? prefix.scalar : 1)) * (atom ? atom.functional(x, direction) : 1) ** exponent
|
58
58
|
end
|
59
59
|
|
60
60
|
def root_terms
|
data/lib/unitwise/unit.rb
CHANGED
data/lib/unitwise/version.rb
CHANGED
@@ -42,6 +42,7 @@ describe Unitwise::Measurement do
|
|
42
42
|
let(:cel) { Unitwise::Measurement.new(22, 'Cel') }
|
43
43
|
let(:k) {Unitwise::Measurement.new(373.15, 'K') }
|
44
44
|
let(:f) {Unitwise::Measurement.new(98.6, '[degF]')}
|
45
|
+
let(:r) { Unitwise::Measurement.new(491.67, '[degR]') }
|
45
46
|
|
46
47
|
describe "#scalar" do
|
47
48
|
it "must return value relative to terminal atoms" do
|
@@ -66,6 +67,12 @@ describe Unitwise::Measurement do
|
|
66
67
|
it "must convert special units to special units" do
|
67
68
|
f.convert('Cel').value.must_equal 37
|
68
69
|
end
|
70
|
+
it "must convert special units to non-special units" do
|
71
|
+
cel.convert("[degR]").value.must_equal 531.27
|
72
|
+
end
|
73
|
+
it "must convert derived units to special units" do
|
74
|
+
r.convert("Cel").value.round.must_equal 0
|
75
|
+
end
|
69
76
|
end
|
70
77
|
|
71
78
|
describe "#*" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unitwise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Josh Lewis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: signed_multiset
|
@@ -210,4 +210,3 @@ test_files:
|
|
210
210
|
- test/unitwise/term_test.rb
|
211
211
|
- test/unitwise/unit_test.rb
|
212
212
|
- test/unitwise_test.rb
|
213
|
-
has_rdoc:
|