measured 2.7.0 → 2.8.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82ffeb317f95fc3c354f43453eabc91b138a5e4f1b50eec651775425a27316e5
4
- data.tar.gz: c664577f19d2ab99b95f7c533fb46323b60390c1b34da1bc3602b27979cddff6
3
+ metadata.gz: 808003a2689c157f3d3a1ef7ff2eb2f1decc242d23c40a536d9bca8c57364a79
4
+ data.tar.gz: 42f4a72969b5331d7cd460f87d5668b3b331001b82f351c221f7153488859be5
5
5
  SHA512:
6
- metadata.gz: 4ae4538c2b2e9b00403b6363d639a6f0959704c4702b65cca3d1cd33d714f2eaf14c4fa4aa446b6247e1f9b7cd7977bc80581115965b21abbd4972b10b2e3eea
7
- data.tar.gz: ee33ab98e63f586bcf1ce299909e4cd6ecc0c6b434e3f2e48340d5dc9f2641a8c34bcc2dd695f9c75f162f413b6533456f6c0ab22d29b3c93c21c186e647b671
6
+ metadata.gz: 4019bd9f128308af57f5ce9440e6a53f05587c1589f120b711c937b70d422a865c14d2e678d4b55bb13054e24a2663b5cb6ef51bfad12e834027eb4a644d5651
7
+ data.tar.gz: caf36d6ad0dbbd0e187adbb0d5a2ddd2718a38ddd67920e628c1d7ad09423f9c35edcef7f05cb863fec8e2849bb0eb8ce4145496aa0749cf2aaafbcd6459ba13
@@ -10,9 +10,9 @@ jobs:
10
10
  strategy:
11
11
  matrix:
12
12
  ruby:
13
- - 2.5
14
- - 2.6
15
- - 2.7
13
+ - '2.6'
14
+ - '2.7'
15
+ - '3.0'
16
16
  gemfile:
17
17
  - Gemfile
18
18
  - gemfiles/activesupport-5.2.gemfile
data/CHANGELOG.md CHANGED
@@ -1,3 +1,31 @@
1
+ Unreleased
2
+ -----
3
+
4
+
5
+
6
+ 2.8.2
7
+ -----
8
+
9
+ * Add cm3 and mm3 to volume. (@fekadeabdejene)
10
+
11
+ 2.8.1
12
+ -----
13
+
14
+ * Allow format without the conversion string. (@saraid)
15
+ * Add special case for zero coercion to allow direct use of `sum` method. (@jmortlock)
16
+ * Add useful numeric methods `finite?`, `infinite?`, `zero?`, `nonzero?`, `positive?` and `negative?`. (@jmortlock)
17
+
18
+ 2.8.0
19
+ -----
20
+
21
+ * Drop support for Ruby 2.5
22
+ * Use Ruby 3.0.2 for development
23
+
24
+ 2.7.1
25
+ -----
26
+
27
+ * Fix Ruby 3.0 compatibility
28
+
1
29
  2.7.0
2
30
  -----
3
31
 
data/README.md CHANGED
@@ -149,6 +149,15 @@ Measured::Weight.new("3.14", "grams").format("%.1<value>f %<unit>s")
149
149
 
150
150
  If no string is passed to the `format` method it defaults to `"%.2<value>f %<unit>s"`.
151
151
 
152
+ If the unit isn't the standard SI unit, it will include a conversion string.
153
+
154
+ ```ruby
155
+ Measured::Weight.new("3.14", "kg").format
156
+ > "3.14 kg (1000/1 g)"
157
+ Measured::Weight.new("3.14", "kg").format(with_conversion_string: false)
158
+ > "3.14 kg"
159
+ ```
160
+
152
161
  ## Units and conversions
153
162
 
154
163
  ### SI units support
data/cache/volume.json CHANGED
@@ -89,6 +89,14 @@
89
89
  "numerator": 1,
90
90
  "denominator": 1000
91
91
  },
92
+ "cm3": {
93
+ "numerator": 1000,
94
+ "denominator": 1
95
+ },
96
+ "mm3": {
97
+ "numerator": 1000000,
98
+ "denominator": 1
99
+ },
92
100
  "in3": {
93
101
  "numerator": 125000000,
94
102
  "denominator": 2048383
@@ -219,6 +227,14 @@
219
227
  "numerator": 1,
220
228
  "denominator": 1000000000000000000000000000
221
229
  },
230
+ "cm3": {
231
+ "numerator": 1,
232
+ "denominator": 1000000000000000000000
233
+ },
234
+ "mm3": {
235
+ "numerator": 1,
236
+ "denominator": 1000000000000000000
237
+ },
222
238
  "in3": {
223
239
  "numerator": 1,
224
240
  "denominator": 16387064000000000000000
@@ -349,6 +365,14 @@
349
365
  "numerator": 1,
350
366
  "denominator": 1000000000000000000000000
351
367
  },
368
+ "cm3": {
369
+ "numerator": 1,
370
+ "denominator": 1000000000000000000
371
+ },
372
+ "mm3": {
373
+ "numerator": 1,
374
+ "denominator": 1000000000000000
375
+ },
352
376
  "in3": {
353
377
  "numerator": 1,
354
378
  "denominator": 16387064000000000000
@@ -479,6 +503,14 @@
479
503
  "numerator": 1,
480
504
  "denominator": 1000000000000000000000
481
505
  },
506
+ "cm3": {
507
+ "numerator": 1,
508
+ "denominator": 1000000000000000
509
+ },
510
+ "mm3": {
511
+ "numerator": 1,
512
+ "denominator": 1000000000000
513
+ },
482
514
  "in3": {
483
515
  "numerator": 1,
484
516
  "denominator": 16387064000000000
@@ -609,6 +641,14 @@
609
641
  "numerator": 1,
610
642
  "denominator": 1000000000000000000
611
643
  },
644
+ "cm3": {
645
+ "numerator": 1,
646
+ "denominator": 1000000000000
647
+ },
648
+ "mm3": {
649
+ "numerator": 1,
650
+ "denominator": 1000000000
651
+ },
612
652
  "in3": {
613
653
  "numerator": 1,
614
654
  "denominator": 16387064000000
@@ -739,6 +779,14 @@
739
779
  "numerator": 1,
740
780
  "denominator": 1000000000000000
741
781
  },
782
+ "cm3": {
783
+ "numerator": 1,
784
+ "denominator": 1000000000
785
+ },
786
+ "mm3": {
787
+ "numerator": 1,
788
+ "denominator": 1000000
789
+ },
742
790
  "in3": {
743
791
  "numerator": 1,
744
792
  "denominator": 16387064000
@@ -869,6 +917,14 @@
869
917
  "numerator": 1,
870
918
  "denominator": 1000000000000
871
919
  },
920
+ "cm3": {
921
+ "numerator": 1,
922
+ "denominator": 1000000
923
+ },
924
+ "mm3": {
925
+ "numerator": 1,
926
+ "denominator": 1000
927
+ },
872
928
  "in3": {
873
929
  "numerator": 1,
874
930
  "denominator": 16387064
@@ -999,6 +1055,14 @@
999
1055
  "numerator": 1,
1000
1056
  "denominator": 1000000000
1001
1057
  },
1058
+ "cm3": {
1059
+ "numerator": 1,
1060
+ "denominator": 1000
1061
+ },
1062
+ "mm3": {
1063
+ "numerator": 1,
1064
+ "denominator": 1
1065
+ },
1002
1066
  "in3": {
1003
1067
  "numerator": 125,
1004
1068
  "denominator": 2048383
@@ -1129,6 +1193,14 @@
1129
1193
  "numerator": 1,
1130
1194
  "denominator": 1000000
1131
1195
  },
1196
+ "cm3": {
1197
+ "numerator": 1,
1198
+ "denominator": 1
1199
+ },
1200
+ "mm3": {
1201
+ "numerator": 1000,
1202
+ "denominator": 1
1203
+ },
1132
1204
  "in3": {
1133
1205
  "numerator": 125000,
1134
1206
  "denominator": 2048383
@@ -1259,6 +1331,14 @@
1259
1331
  "numerator": 1,
1260
1332
  "denominator": 100000
1261
1333
  },
1334
+ "cm3": {
1335
+ "numerator": 10,
1336
+ "denominator": 1
1337
+ },
1338
+ "mm3": {
1339
+ "numerator": 10000,
1340
+ "denominator": 1
1341
+ },
1262
1342
  "in3": {
1263
1343
  "numerator": 1250000,
1264
1344
  "denominator": 2048383
@@ -1389,6 +1469,14 @@
1389
1469
  "numerator": 1,
1390
1470
  "denominator": 10000
1391
1471
  },
1472
+ "cm3": {
1473
+ "numerator": 100,
1474
+ "denominator": 1
1475
+ },
1476
+ "mm3": {
1477
+ "numerator": 100000,
1478
+ "denominator": 1
1479
+ },
1392
1480
  "in3": {
1393
1481
  "numerator": 12500000,
1394
1482
  "denominator": 2048383
@@ -1519,6 +1607,14 @@
1519
1607
  "numerator": 1,
1520
1608
  "denominator": 100
1521
1609
  },
1610
+ "cm3": {
1611
+ "numerator": 10000,
1612
+ "denominator": 1
1613
+ },
1614
+ "mm3": {
1615
+ "numerator": 10000000,
1616
+ "denominator": 1
1617
+ },
1522
1618
  "in3": {
1523
1619
  "numerator": 1250000000,
1524
1620
  "denominator": 2048383
@@ -1649,6 +1745,14 @@
1649
1745
  "numerator": 1,
1650
1746
  "denominator": 10
1651
1747
  },
1748
+ "cm3": {
1749
+ "numerator": 100000,
1750
+ "denominator": 1
1751
+ },
1752
+ "mm3": {
1753
+ "numerator": 100000000,
1754
+ "denominator": 1
1755
+ },
1652
1756
  "in3": {
1653
1757
  "numerator": 12500000000,
1654
1758
  "denominator": 2048383
@@ -1779,6 +1883,14 @@
1779
1883
  "numerator": 1,
1780
1884
  "denominator": 1
1781
1885
  },
1886
+ "cm3": {
1887
+ "numerator": 1000000,
1888
+ "denominator": 1
1889
+ },
1890
+ "mm3": {
1891
+ "numerator": 1000000000,
1892
+ "denominator": 1
1893
+ },
1782
1894
  "in3": {
1783
1895
  "numerator": 125000000000,
1784
1896
  "denominator": 2048383
@@ -1909,6 +2021,14 @@
1909
2021
  "numerator": 1000,
1910
2022
  "denominator": 1
1911
2023
  },
2024
+ "cm3": {
2025
+ "numerator": 1000000000,
2026
+ "denominator": 1
2027
+ },
2028
+ "mm3": {
2029
+ "numerator": 1000000000000,
2030
+ "denominator": 1
2031
+ },
1912
2032
  "in3": {
1913
2033
  "numerator": 125000000000000,
1914
2034
  "denominator": 2048383
@@ -2039,6 +2159,14 @@
2039
2159
  "numerator": 1000000,
2040
2160
  "denominator": 1
2041
2161
  },
2162
+ "cm3": {
2163
+ "numerator": 1000000000000,
2164
+ "denominator": 1
2165
+ },
2166
+ "mm3": {
2167
+ "numerator": 1000000000000000,
2168
+ "denominator": 1
2169
+ },
2042
2170
  "in3": {
2043
2171
  "numerator": 125000000000000000,
2044
2172
  "denominator": 2048383
@@ -2169,6 +2297,14 @@
2169
2297
  "numerator": 1000000000,
2170
2298
  "denominator": 1
2171
2299
  },
2300
+ "cm3": {
2301
+ "numerator": 1000000000000000,
2302
+ "denominator": 1
2303
+ },
2304
+ "mm3": {
2305
+ "numerator": 1000000000000000000,
2306
+ "denominator": 1
2307
+ },
2172
2308
  "in3": {
2173
2309
  "numerator": 125000000000000000000,
2174
2310
  "denominator": 2048383
@@ -2299,6 +2435,14 @@
2299
2435
  "numerator": 1000000000000,
2300
2436
  "denominator": 1
2301
2437
  },
2438
+ "cm3": {
2439
+ "numerator": 1000000000000000000,
2440
+ "denominator": 1
2441
+ },
2442
+ "mm3": {
2443
+ "numerator": 1000000000000000000000,
2444
+ "denominator": 1
2445
+ },
2302
2446
  "in3": {
2303
2447
  "numerator": 125000000000000000000000,
2304
2448
  "denominator": 2048383
@@ -2429,6 +2573,14 @@
2429
2573
  "numerator": 1000000000000000,
2430
2574
  "denominator": 1
2431
2575
  },
2576
+ "cm3": {
2577
+ "numerator": 1000000000000000000000,
2578
+ "denominator": 1
2579
+ },
2580
+ "mm3": {
2581
+ "numerator": 1000000000000000000000000,
2582
+ "denominator": 1
2583
+ },
2432
2584
  "in3": {
2433
2585
  "numerator": 125000000000000000000000000,
2434
2586
  "denominator": 2048383
@@ -2559,6 +2711,14 @@
2559
2711
  "numerator": 1000000000000000000,
2560
2712
  "denominator": 1
2561
2713
  },
2714
+ "cm3": {
2715
+ "numerator": 1000000000000000000000000,
2716
+ "denominator": 1
2717
+ },
2718
+ "mm3": {
2719
+ "numerator": 1000000000000000000000000000,
2720
+ "denominator": 1
2721
+ },
2562
2722
  "in3": {
2563
2723
  "numerator": 125000000000000000000000000000,
2564
2724
  "denominator": 2048383
@@ -2689,6 +2849,14 @@
2689
2849
  "numerator": 1000000000000000000000,
2690
2850
  "denominator": 1
2691
2851
  },
2852
+ "cm3": {
2853
+ "numerator": 1000000000000000000000000000,
2854
+ "denominator": 1
2855
+ },
2856
+ "mm3": {
2857
+ "numerator": 1000000000000000000000000000000,
2858
+ "denominator": 1
2859
+ },
2692
2860
  "in3": {
2693
2861
  "numerator": 125000000000000000000000000000000,
2694
2862
  "denominator": 2048383
@@ -2819,6 +2987,14 @@
2819
2987
  "numerator": 1,
2820
2988
  "denominator": 1000000000000000000000
2821
2989
  },
2990
+ "cm3": {
2991
+ "numerator": 1000000,
2992
+ "denominator": 1
2993
+ },
2994
+ "mm3": {
2995
+ "numerator": 1000000000,
2996
+ "denominator": 1
2997
+ },
2822
2998
  "in3": {
2823
2999
  "numerator": 125000000000,
2824
3000
  "denominator": 2048383
@@ -2860,6 +3036,282 @@
2860
3036
  "denominator": 473176473
2861
3037
  }
2862
3038
  },
3039
+ "cm3": {
3040
+ "cm3": {
3041
+ "numerator": 1,
3042
+ "denominator": 1
3043
+ },
3044
+ "l": {
3045
+ "numerator": 1,
3046
+ "denominator": 1000
3047
+ },
3048
+ "yl": {
3049
+ "numerator": 1000000000000000000000,
3050
+ "denominator": 1
3051
+ },
3052
+ "zl": {
3053
+ "numerator": 1000000000000000000,
3054
+ "denominator": 1
3055
+ },
3056
+ "al": {
3057
+ "numerator": 1000000000000000,
3058
+ "denominator": 1
3059
+ },
3060
+ "fl": {
3061
+ "numerator": 1000000000000,
3062
+ "denominator": 1
3063
+ },
3064
+ "pl": {
3065
+ "numerator": 1000000000,
3066
+ "denominator": 1
3067
+ },
3068
+ "nl": {
3069
+ "numerator": 1000000,
3070
+ "denominator": 1
3071
+ },
3072
+ "μl": {
3073
+ "numerator": 1000,
3074
+ "denominator": 1
3075
+ },
3076
+ "ml": {
3077
+ "numerator": 1,
3078
+ "denominator": 1
3079
+ },
3080
+ "cl": {
3081
+ "numerator": 1,
3082
+ "denominator": 10
3083
+ },
3084
+ "dl": {
3085
+ "numerator": 1,
3086
+ "denominator": 100
3087
+ },
3088
+ "dal": {
3089
+ "numerator": 1,
3090
+ "denominator": 10000
3091
+ },
3092
+ "hl": {
3093
+ "numerator": 1,
3094
+ "denominator": 100000
3095
+ },
3096
+ "kl": {
3097
+ "numerator": 1,
3098
+ "denominator": 1000000
3099
+ },
3100
+ "Ml": {
3101
+ "numerator": 1,
3102
+ "denominator": 1000000000
3103
+ },
3104
+ "Gl": {
3105
+ "numerator": 1,
3106
+ "denominator": 1000000000000
3107
+ },
3108
+ "Tl": {
3109
+ "numerator": 1,
3110
+ "denominator": 1000000000000000
3111
+ },
3112
+ "Pl": {
3113
+ "numerator": 1,
3114
+ "denominator": 1000000000000000000
3115
+ },
3116
+ "El": {
3117
+ "numerator": 1,
3118
+ "denominator": 1000000000000000000000
3119
+ },
3120
+ "Zl": {
3121
+ "numerator": 1,
3122
+ "denominator": 1000000000000000000000000
3123
+ },
3124
+ "Yl": {
3125
+ "numerator": 1,
3126
+ "denominator": 1000000000000000000000000000
3127
+ },
3128
+ "m3": {
3129
+ "numerator": 1,
3130
+ "denominator": 1000000
3131
+ },
3132
+ "mm3": {
3133
+ "numerator": 1000,
3134
+ "denominator": 1
3135
+ },
3136
+ "in3": {
3137
+ "numerator": 125000,
3138
+ "denominator": 2048383
3139
+ },
3140
+ "ft3": {
3141
+ "numerator": 15625,
3142
+ "denominator": 442450728
3143
+ },
3144
+ "gal": {
3145
+ "numerator": 100,
3146
+ "denominator": 454609
3147
+ },
3148
+ "us_gal": {
3149
+ "numerator": 125000,
3150
+ "denominator": 473176473
3151
+ },
3152
+ "qt": {
3153
+ "numerator": 400,
3154
+ "denominator": 454609
3155
+ },
3156
+ "us_qt": {
3157
+ "numerator": 500000,
3158
+ "denominator": 473176473
3159
+ },
3160
+ "pt": {
3161
+ "numerator": 800,
3162
+ "denominator": 454609
3163
+ },
3164
+ "us_pt": {
3165
+ "numerator": 1000000,
3166
+ "denominator": 473176473
3167
+ },
3168
+ "oz": {
3169
+ "numerator": 16000,
3170
+ "denominator": 454609
3171
+ },
3172
+ "us_oz": {
3173
+ "numerator": 16000000,
3174
+ "denominator": 473176473
3175
+ }
3176
+ },
3177
+ "mm3": {
3178
+ "mm3": {
3179
+ "numerator": 1,
3180
+ "denominator": 1
3181
+ },
3182
+ "l": {
3183
+ "numerator": 1,
3184
+ "denominator": 1000000
3185
+ },
3186
+ "yl": {
3187
+ "numerator": 1000000000000000000,
3188
+ "denominator": 1
3189
+ },
3190
+ "zl": {
3191
+ "numerator": 1000000000000000,
3192
+ "denominator": 1
3193
+ },
3194
+ "al": {
3195
+ "numerator": 1000000000000,
3196
+ "denominator": 1
3197
+ },
3198
+ "fl": {
3199
+ "numerator": 1000000000,
3200
+ "denominator": 1
3201
+ },
3202
+ "pl": {
3203
+ "numerator": 1000000,
3204
+ "denominator": 1
3205
+ },
3206
+ "nl": {
3207
+ "numerator": 1000,
3208
+ "denominator": 1
3209
+ },
3210
+ "μl": {
3211
+ "numerator": 1,
3212
+ "denominator": 1
3213
+ },
3214
+ "ml": {
3215
+ "numerator": 1,
3216
+ "denominator": 1000
3217
+ },
3218
+ "cl": {
3219
+ "numerator": 1,
3220
+ "denominator": 10000
3221
+ },
3222
+ "dl": {
3223
+ "numerator": 1,
3224
+ "denominator": 100000
3225
+ },
3226
+ "dal": {
3227
+ "numerator": 1,
3228
+ "denominator": 10000000
3229
+ },
3230
+ "hl": {
3231
+ "numerator": 1,
3232
+ "denominator": 100000000
3233
+ },
3234
+ "kl": {
3235
+ "numerator": 1,
3236
+ "denominator": 1000000000
3237
+ },
3238
+ "Ml": {
3239
+ "numerator": 1,
3240
+ "denominator": 1000000000000
3241
+ },
3242
+ "Gl": {
3243
+ "numerator": 1,
3244
+ "denominator": 1000000000000000
3245
+ },
3246
+ "Tl": {
3247
+ "numerator": 1,
3248
+ "denominator": 1000000000000000000
3249
+ },
3250
+ "Pl": {
3251
+ "numerator": 1,
3252
+ "denominator": 1000000000000000000000
3253
+ },
3254
+ "El": {
3255
+ "numerator": 1,
3256
+ "denominator": 1000000000000000000000000
3257
+ },
3258
+ "Zl": {
3259
+ "numerator": 1,
3260
+ "denominator": 1000000000000000000000000000
3261
+ },
3262
+ "Yl": {
3263
+ "numerator": 1,
3264
+ "denominator": 1000000000000000000000000000000
3265
+ },
3266
+ "m3": {
3267
+ "numerator": 1,
3268
+ "denominator": 1000000000
3269
+ },
3270
+ "cm3": {
3271
+ "numerator": 1,
3272
+ "denominator": 1000
3273
+ },
3274
+ "in3": {
3275
+ "numerator": 125,
3276
+ "denominator": 2048383
3277
+ },
3278
+ "ft3": {
3279
+ "numerator": 125,
3280
+ "denominator": 3539605824
3281
+ },
3282
+ "gal": {
3283
+ "numerator": 1,
3284
+ "denominator": 4546090
3285
+ },
3286
+ "us_gal": {
3287
+ "numerator": 125,
3288
+ "denominator": 473176473
3289
+ },
3290
+ "qt": {
3291
+ "numerator": 2,
3292
+ "denominator": 2273045
3293
+ },
3294
+ "us_qt": {
3295
+ "numerator": 500,
3296
+ "denominator": 473176473
3297
+ },
3298
+ "pt": {
3299
+ "numerator": 4,
3300
+ "denominator": 2273045
3301
+ },
3302
+ "us_pt": {
3303
+ "numerator": 1000,
3304
+ "denominator": 473176473
3305
+ },
3306
+ "oz": {
3307
+ "numerator": 16,
3308
+ "denominator": 454609
3309
+ },
3310
+ "us_oz": {
3311
+ "numerator": 16000,
3312
+ "denominator": 473176473
3313
+ }
3314
+ },
2863
3315
  "in3": {
2864
3316
  "in3": {
2865
3317
  "numerator": 1,
@@ -2953,6 +3405,14 @@
2953
3405
  "numerator": 2048383,
2954
3406
  "denominator": 125000000000
2955
3407
  },
3408
+ "cm3": {
3409
+ "numerator": 2048383,
3410
+ "denominator": 125000
3411
+ },
3412
+ "mm3": {
3413
+ "numerator": 2048383,
3414
+ "denominator": 125
3415
+ },
2956
3416
  "ft3": {
2957
3417
  "numerator": 1,
2958
3418
  "denominator": 1728
@@ -3083,6 +3543,14 @@
3083
3543
  "numerator": 55306341,
3084
3544
  "denominator": 1953125000
3085
3545
  },
3546
+ "cm3": {
3547
+ "numerator": 442450728,
3548
+ "denominator": 15625
3549
+ },
3550
+ "mm3": {
3551
+ "numerator": 3539605824,
3552
+ "denominator": 125
3553
+ },
3086
3554
  "in3": {
3087
3555
  "numerator": 1728,
3088
3556
  "denominator": 1
@@ -3213,6 +3681,14 @@
3213
3681
  "numerator": 454609,
3214
3682
  "denominator": 100000000
3215
3683
  },
3684
+ "cm3": {
3685
+ "numerator": 454609,
3686
+ "denominator": 100
3687
+ },
3688
+ "mm3": {
3689
+ "numerator": 4546090,
3690
+ "denominator": 1
3691
+ },
3216
3692
  "in3": {
3217
3693
  "numerator": 568261250,
3218
3694
  "denominator": 2048383
@@ -3343,6 +3819,14 @@
3343
3819
  "numerator": 473176473,
3344
3820
  "denominator": 125000000000
3345
3821
  },
3822
+ "cm3": {
3823
+ "numerator": 473176473,
3824
+ "denominator": 125000
3825
+ },
3826
+ "mm3": {
3827
+ "numerator": 473176473,
3828
+ "denominator": 125
3829
+ },
3346
3830
  "in3": {
3347
3831
  "numerator": 231,
3348
3832
  "denominator": 1
@@ -3473,6 +3957,14 @@
3473
3957
  "numerator": 454609,
3474
3958
  "denominator": 400000000
3475
3959
  },
3960
+ "cm3": {
3961
+ "numerator": 454609,
3962
+ "denominator": 400
3963
+ },
3964
+ "mm3": {
3965
+ "numerator": 2273045,
3966
+ "denominator": 2
3967
+ },
3476
3968
  "in3": {
3477
3969
  "numerator": 284130625,
3478
3970
  "denominator": 4096766
@@ -3603,6 +4095,14 @@
3603
4095
  "numerator": 473176473,
3604
4096
  "denominator": 500000000000
3605
4097
  },
4098
+ "cm3": {
4099
+ "numerator": 473176473,
4100
+ "denominator": 500000
4101
+ },
4102
+ "mm3": {
4103
+ "numerator": 473176473,
4104
+ "denominator": 500
4105
+ },
3606
4106
  "in3": {
3607
4107
  "numerator": 231,
3608
4108
  "denominator": 4
@@ -3733,6 +4233,14 @@
3733
4233
  "numerator": 454609,
3734
4234
  "denominator": 800000000
3735
4235
  },
4236
+ "cm3": {
4237
+ "numerator": 454609,
4238
+ "denominator": 800
4239
+ },
4240
+ "mm3": {
4241
+ "numerator": 2273045,
4242
+ "denominator": 4
4243
+ },
3736
4244
  "in3": {
3737
4245
  "numerator": 284130625,
3738
4246
  "denominator": 8193532
@@ -3863,6 +4371,14 @@
3863
4371
  "numerator": 473176473,
3864
4372
  "denominator": 1000000000000
3865
4373
  },
4374
+ "cm3": {
4375
+ "numerator": 473176473,
4376
+ "denominator": 1000000
4377
+ },
4378
+ "mm3": {
4379
+ "numerator": 473176473,
4380
+ "denominator": 1000
4381
+ },
3866
4382
  "in3": {
3867
4383
  "numerator": 231,
3868
4384
  "denominator": 8
@@ -3993,6 +4509,14 @@
3993
4509
  "numerator": 454609,
3994
4510
  "denominator": 16000000000
3995
4511
  },
4512
+ "cm3": {
4513
+ "numerator": 454609,
4514
+ "denominator": 16000
4515
+ },
4516
+ "mm3": {
4517
+ "numerator": 454609,
4518
+ "denominator": 16
4519
+ },
3996
4520
  "in3": {
3997
4521
  "numerator": 56826125,
3998
4522
  "denominator": 32774128
@@ -4123,6 +4647,14 @@
4123
4647
  "numerator": 473176473,
4124
4648
  "denominator": 16000000000000
4125
4649
  },
4650
+ "cm3": {
4651
+ "numerator": 473176473,
4652
+ "denominator": 16000000
4653
+ },
4654
+ "mm3": {
4655
+ "numerator": 473176473,
4656
+ "denominator": 16000
4657
+ },
4126
4658
  "in3": {
4127
4659
  "numerator": 231,
4128
4660
  "denominator": 128
data/dev.yml CHANGED
@@ -2,7 +2,7 @@ name: measured
2
2
 
3
3
  up:
4
4
  - ruby:
5
- version: 2.6.3
5
+ version: 3.0.2
6
6
  - bundler
7
7
 
8
8
  commands:
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module Measured::Arithmetic
3
+ extend Forwardable
4
+ def_delegators :@value, :zero?, :positive?, :negative?, :finite?, :infinite?
5
+
3
6
  def +(other)
4
7
  arithmetic_operation(other, :+)
5
8
  end
@@ -19,6 +22,8 @@ module Measured::Arithmetic
19
22
  def coerce(other)
20
23
  if other.is_a?(self.class)
21
24
  [other, self]
25
+ elsif other.is_a?(Numeric) && other.zero?
26
+ [self.class.new(other, self.unit), self]
22
27
  else
23
28
  raise TypeError, "Cannot coerce #{other.class} to #{self.class}"
24
29
  end
@@ -28,6 +33,10 @@ module Measured::Arithmetic
28
33
  raise TypeError, "#{self.class} cannot be converted to an integer"
29
34
  end
30
35
 
36
+ def nonzero?
37
+ value.nonzero? ? self : false
38
+ end
39
+
31
40
  private
32
41
 
33
42
  def arithmetic_operation(other, operator)
@@ -37,11 +37,17 @@ module Measured::Cache
37
37
  end
38
38
 
39
39
  def decode(table)
40
- table.each_with_object(table.dup) do |(k1, v1), accu|
41
- v1.each do |k2, v2|
42
- if v2.is_a?(Hash)
43
- accu[k1][k2] = Rational(v2["numerator"], v2["denominator"])
40
+ table.transform_values do |value1|
41
+ if value1.is_a?(Hash)
42
+ value1.transform_values do |value2|
43
+ if value2.is_a?(Hash)
44
+ Rational(value2["numerator"], value2["denominator"])
45
+ else
46
+ value2
47
+ end
44
48
  end
49
+ else
50
+ value1
45
51
  end
46
52
  end
47
53
  end
@@ -43,10 +43,10 @@ class Measured::Measurable < Numeric
43
43
  self.class.new(new_value, new_unit)
44
44
  end
45
45
 
46
- def format(format_string=nil)
46
+ def format(format_string=nil, with_conversion_string: true)
47
47
  kwargs = {
48
48
  value: self.value,
49
- unit: self.unit,
49
+ unit: self.unit.to_s(with_conversion_string: with_conversion_string),
50
50
  }
51
51
  (format_string || DEFAULT_FORMAT_STRING) % kwargs
52
52
  end
data/lib/measured/unit.rb CHANGED
@@ -23,8 +23,8 @@ class Measured::Unit
23
23
  )
24
24
  end
25
25
 
26
- def to_s
27
- if @conversion_string
26
+ def to_s(with_conversion_string: true)
27
+ if with_conversion_string && @conversion_string
28
28
  "#{name} (#{@conversion_string})".freeze
29
29
  else
30
30
  name
@@ -3,6 +3,8 @@ Measured::Volume = Measured.build do
3
3
  si_unit :l, aliases: [:liter, :litre, :liters, :litres]
4
4
 
5
5
  unit :m3, value: "1000 l", aliases: [:cubic_meter, :cubic_metre, :cubic_meters, :cubic_metres]
6
+ unit :cm3, value: "0.001 l", aliases: [:cubic_centimeter, :cubic_centimetre, :cubic_centimeters, :cubic_centimetres]
7
+ unit :mm3, value: "0.000001 l", aliases: [:cubic_millimeter, :cubic_millimetre, :cubic_millimeters, :cubic_millimetres]
6
8
  unit :in3, value: "0.016387064 l", aliases: [:cubic_inch, :cubic_inches]
7
9
  unit :ft3, value: "1728 in3", aliases: [:cubic_foot, :cubic_feet]
8
10
  unit :gal, value: "4.54609 l", aliases: [:imp_gal, :imperial_gallon, :imp_gals, :imperial_gallons]
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Measured
3
- VERSION = "2.7.0"
3
+ VERSION = "2.8.2"
4
4
  end
@@ -8,6 +8,41 @@ class Measured::ArithmeticTest < ActiveSupport::TestCase
8
8
  @four = Magic.new(4, :magic_missile)
9
9
  end
10
10
 
11
+ test "should be able to sum same units" do
12
+ assert_equal Magic.new(9, :magic_missile), [@two, @three, @four].sum
13
+ end
14
+
15
+ test 'can check for finite?' do
16
+ assert Magic.new(0, :magic_missile).finite?
17
+ refute Magic.new(Float::INFINITY, :magic_missile).finite?
18
+ end
19
+
20
+ test 'can check for infinite?' do
21
+ assert Magic.new(Float::INFINITY, :magic_missile).infinite?
22
+ refute Magic.new(0, :magic_missile).infinite?
23
+ end
24
+
25
+ test 'can check for zero?' do
26
+ assert Magic.new(0, :magic_missile).zero?
27
+ refute Magic.new(1, :magic_missile).zero?
28
+ end
29
+
30
+ test 'can check for nonzero?' do
31
+ assert_equal Magic.new(10, :magic_missile), Magic.new(10, :magic_missile).nonzero?
32
+ assert Magic.new(10, :magic_missile).nonzero?
33
+ refute Magic.new(0, :magic_missile).nonzero?
34
+ end
35
+
36
+ test 'can check for positive?' do
37
+ assert Magic.new(1, :magic_missile).positive?
38
+ refute Magic.new(-1, :magic_missile).positive?
39
+ end
40
+
41
+ test 'can check for negative?' do
42
+ assert Magic.new(-1, :magic_missile).negative?
43
+ refute Magic.new(1, :magic_missile).negative?
44
+ end
45
+
11
46
  test "#+ should add together same units" do
12
47
  assert_equal Magic.new(5, :magic_missile), @two + @three
13
48
  assert_equal Magic.new(5, :magic_missile), @three + @two
@@ -232,6 +232,11 @@ class Measured::MeasurableTest < ActiveSupport::TestCase
232
232
  assert_equal "9.34 magic_missile", Magic.new(9.342, :magic_missile).format
233
233
  end
234
234
 
235
+ test "#format can drop the conversion amount" do
236
+ assert_equal "1.00 fireball (2/3 magic_missile)", Magic.new(1, :fireball).format
237
+ assert_equal "1.00 fireball", Magic.new(1, :fireball).format(with_conversion_string: false)
238
+ end
239
+
235
240
  test "#humanize outputs the number and the unit properly pluralized" do
236
241
  assert_equal "1 fireball", Magic.new("1", :fire).humanize
237
242
  assert_equal "10 fireballs", Magic.new(10, :fire).humanize
@@ -246,12 +251,6 @@ class Measured::MeasurableTest < ActiveSupport::TestCase
246
251
  assert_equal "#<Magic: 1.234 #<Measured::Unit: magic_missile (magic_missiles, magic missile)>>", Magic.new(1.234, :magic_missile).inspect
247
252
  end
248
253
 
249
- test "#zero? always returns false" do
250
- refute_predicate Magic.new(0, :fire), :zero?
251
- refute_predicate Magic.new(0.0, :fire), :zero?
252
- refute_predicate Magic.new("0.0", :fire), :zero?
253
- end
254
-
255
254
  test "#<=> compares regardless of the unit" do
256
255
  assert_equal (-1), @magic <=> Magic.new(20, :fire)
257
256
  assert_equal 1, @magic <=> Magic.new(9, :magic_missile)
data/test/unit_test.rb CHANGED
@@ -43,6 +43,10 @@ class Measured::UnitTest < ActiveSupport::TestCase
43
43
  assert_equal "pie (1/2 sweet)", Measured::Unit.new(:pie, aliases: ["cake"], value: "0.5 sweet").to_s
44
44
  end
45
45
 
46
+ test "#to_s can drop the conversion amount" do
47
+ assert_equal "pie", Measured::Unit.new(:pie).to_s(with_conversion_string: false)
48
+ end
49
+
46
50
  test "#inspect returns an expected string" do
47
51
  assert_equal "#<Measured::Unit: pie>", Measured::Unit.new(:pie).inspect
48
52
  assert_equal "#<Measured::Unit: pie (cake, semi-sweet)>", Measured::Unit.new(:pie, aliases: ["cake", "semi-sweet"]).inspect
@@ -19,6 +19,16 @@ class Measured::VolumeTest < ActiveSupport::TestCase
19
19
  liters
20
20
  litres
21
21
  ft3
22
+ cm3
23
+ cubic_centimeter
24
+ cubic_centimeters
25
+ cubic_centimetre
26
+ cubic_centimetres
27
+ mm3
28
+ cubic_millimeter
29
+ cubic_millimeters
30
+ cubic_millimetre
31
+ cubic_millimetres
22
32
  cubic_foot
23
33
  cubic_feet
24
34
  in3
@@ -67,7 +77,7 @@ class Measured::VolumeTest < ActiveSupport::TestCase
67
77
  end
68
78
 
69
79
  test ".unit_names should be the list of base unit names" do
70
- expected_units = %w(l m3 ft3 in3 gal us_gal qt us_qt pt us_pt oz us_oz)
80
+ expected_units = %w(l m3 ft3 in3 gal us_gal qt us_qt pt us_pt oz us_oz mm3 cm3)
71
81
  expected_units += Measured::UnitSystemBuilder::SI_PREFIXES.map { |short, _, _| "#{short}l" }
72
82
  assert_equal expected_units.sort, Measured::Volume.unit_names
73
83
  end
@@ -124,6 +134,102 @@ class Measured::VolumeTest < ActiveSupport::TestCase
124
134
  test ".convert_to from us_oz to us_oz" do
125
135
  assert_conversion Measured::Volume, "2000 us_oz", "2000 us_oz"
126
136
  end
137
+
138
+ test ".convert_to from mm3 to mm3" do
139
+ assert_conversion Measured::Volume, "20000 mm3", "20000 mm3"
140
+ end
141
+
142
+ test ".convert_to from cm3 to cm3" do
143
+ assert_conversion Measured::Volume, "20000 cm3", "20000 cm3"
144
+ end
145
+
146
+ test ".convert_to from mm3 to m3" do
147
+ assert_conversion Measured::Volume, "20000 mm3", "0.00002 m3"
148
+ end
149
+
150
+ test ".convert_to from mm3 to ft3" do
151
+ assert_conversion Measured::Volume, "20000 mm3", "0.00070629333 ft3"
152
+ end
153
+
154
+ test ".convert_to from mm3 to in3" do
155
+ assert_conversion Measured::Volume, "20000 mm3", "1.2204749 in3"
156
+ end
157
+
158
+ test ".convert_to from mm3 to gal" do
159
+ assert_conversion Measured::Volume, "20000 mm3", "0.004399384965981756 gal"
160
+ end
161
+
162
+ test ".convert_to from mm3 to us_gal" do
163
+ assert_conversion Measured::Volume, "20000 mm3", "0.005283441047162969 us_gal"
164
+ end
165
+
166
+ test ".convert_to from mm3 to qt" do
167
+ assert_conversion Measured::Volume, "20000 mm3", "0.01759754 qt"
168
+ end
169
+
170
+ test ".convert_to from mm3 to us_qt" do
171
+ assert_conversion Measured::Volume, "20000 mm3", "0.021133764 us_qt"
172
+ end
173
+
174
+ test ".convert_to from mm3 to pt" do
175
+ assert_conversion Measured::Volume, "20000 mm3", "0.03519508 pt"
176
+ end
177
+
178
+ test ".convert_to from mm3 to us_pt" do
179
+ assert_conversion Measured::Volume, "20000 mm3", "0.042267528 us_pt"
180
+ end
181
+
182
+ test ".convert_to from mm3 to oz" do
183
+ assert_conversion Measured::Volume, "20000 mm3", "0.70390159 oz"
184
+ end
185
+
186
+ test ".convert_to from mm3 to us_oz" do
187
+ assert_conversion Measured::Volume, "20000 mm3", "0.67628045 us_oz"
188
+ end
189
+
190
+ test ".convert_to from cm3 to m3" do
191
+ assert_conversion Measured::Volume, "20000 cm3", "0.02 m3"
192
+ end
193
+
194
+ test ".convert_to from cm3 to ft3" do
195
+ assert_conversion Measured::Volume, "20000 cm3", "0.70629333 ft3"
196
+ end
197
+
198
+ test ".convert_to from cm3 to in3" do
199
+ assert_conversion Measured::Volume, "20000 cm3", "1220.4748818946457 in3"
200
+ end
201
+
202
+ test ".convert_to from cm3 to gal" do
203
+ assert_conversion Measured::Volume, "20000 cm3", "4.399384965981756 gal"
204
+ end
205
+
206
+ test ".convert_to from cm3 to us_gal" do
207
+ assert_conversion Measured::Volume, "20000 cm3", "5.283441047162969 us_gal"
208
+ end
209
+
210
+ test ".convert_to from cm3 to qt" do
211
+ assert_conversion Measured::Volume, "20000 cm3", "17.59754 qt"
212
+ end
213
+
214
+ test ".convert_to from cm3 to us_qt" do
215
+ assert_conversion Measured::Volume, "20000 cm3", "21.133764 us_qt"
216
+ end
217
+
218
+ test ".convert_to from cm3 to pt" do
219
+ assert_conversion Measured::Volume, "20000 cm3", "35.19508 pt"
220
+ end
221
+
222
+ test ".convert_to from cm3 to us_pt" do
223
+ assert_conversion Measured::Volume, "20000 cm3", "42.267528 us_pt"
224
+ end
225
+
226
+ test ".convert_to from cm3 to oz" do
227
+ assert_conversion Measured::Volume, "20000 cm3", "703.9015945570809 oz"
228
+ end
229
+
230
+ test ".convert_to from cm3 to us_oz" do
231
+ assert_conversion Measured::Volume, "20000 cm3", "676.28045403686 us_oz"
232
+ end
127
233
 
128
234
  test ".convert_to from ml to m3" do
129
235
  assert_conversion Measured::Volume, "2000 ml", "0.002 m3"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: measured
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin McPhillips
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-05-06 00:00:00.000000000 Z
13
+ date: 2021-12-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -180,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
180
180
  - !ruby/object:Gem::Version
181
181
  version: '0'
182
182
  requirements: []
183
- rubygems_version: 3.0.3
183
+ rubygems_version: 3.2.20
184
184
  signing_key:
185
185
  specification_version: 4
186
186
  summary: Encapsulate measurements with their units in Ruby