ruby-units 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.txt +4 -0
- data/VERSION +1 -1
- data/lib/ruby_units/date.rb +2 -2
- data/lib/ruby_units/time.rb +2 -2
- data/lib/ruby_units/unit.rb +68 -28
- data/lib/ruby_units/unit_definitions/base.rb +28 -28
- data/lib/ruby_units/unit_definitions/prefix.rb +30 -32
- data/lib/ruby_units/unit_definitions/standard.rb +108 -108
- data/ruby-units.gemspec +8 -4
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52d0abf6dc2d186c597aa3543dfb64a2e4e58437
|
4
|
+
data.tar.gz: bc9f92f2eaf3eeefb1df33699785d21a2ff9fcf8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf20400a8552f515beb913042d5d8736402ac244736718fe515058b5556b4f13b3b04fc8091f65fde2adcdb5da8af48af5f32a54b7bdf51f1824ba1371df9f3b
|
7
|
+
data.tar.gz: '066711448923f74c7f9995bfd3f1c700495018ffe142ea48e1dbe1158e3842f3d19a363268ecd38546fc35768196334f8fbd05cf3aae693335217e43b3c70d83'
|
data/CHANGELOG.txt
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
Change Log for Ruby-units
|
2
2
|
=========================
|
3
|
+
2017-12-07 2.2.1 * fix an issue with formatting of rational scalars (see #159)
|
4
|
+
2017-08-07 2.2.0 * add support for ruby 2.4.1
|
5
|
+
* drop support for ruby 2.1.0
|
6
|
+
* remove dependency on mathn (see #157)
|
3
7
|
2016-12-28 2.1.0 * add support for ruby 2.4.0
|
4
8
|
* allow configuration for optional separator on output
|
5
9
|
* Fix issue #105 -- change 'grad' to 'gon'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.2.
|
1
|
+
2.2.1
|
data/lib/ruby_units/date.rb
CHANGED
@@ -9,7 +9,7 @@ class Date
|
|
9
9
|
def +(other)
|
10
10
|
case other
|
11
11
|
when RubyUnits::Unit
|
12
|
-
other = other.convert_to('d').round if %w
|
12
|
+
other = other.convert_to('d').round if %w[y decade century].include? other.units
|
13
13
|
unit_date_add(other.convert_to('day').scalar)
|
14
14
|
else
|
15
15
|
unit_date_add(other)
|
@@ -22,7 +22,7 @@ class Date
|
|
22
22
|
def -(other)
|
23
23
|
case other
|
24
24
|
when RubyUnits::Unit
|
25
|
-
other = other.convert_to('d').round if %w
|
25
|
+
other = other.convert_to('d').round if %w[y decade century].include? other.units
|
26
26
|
unit_date_sub(other.convert_to('day').scalar)
|
27
27
|
else
|
28
28
|
unit_date_sub(other)
|
data/lib/ruby_units/time.rb
CHANGED
@@ -45,7 +45,7 @@ class Time
|
|
45
45
|
def +(other)
|
46
46
|
case other
|
47
47
|
when RubyUnits::Unit
|
48
|
-
other = other.convert_to('d').round.convert_to('s') if %w
|
48
|
+
other = other.convert_to('d').round.convert_to('s') if %w[y decade century].include? other.units
|
49
49
|
begin
|
50
50
|
unit_add(other.convert_to('s').scalar)
|
51
51
|
rescue RangeError
|
@@ -69,7 +69,7 @@ class Time
|
|
69
69
|
def -(other)
|
70
70
|
case other
|
71
71
|
when RubyUnits::Unit
|
72
|
-
other = other.convert_to('d').round.convert_to('s') if %w
|
72
|
+
other = other.convert_to('d').round.convert_to('s') if %w[y decade century].include? other.units
|
73
73
|
begin
|
74
74
|
unit_sub(other.convert_to('s').scalar)
|
75
75
|
rescue RangeError
|
data/lib/ruby_units/unit.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
# encoding: utf-8
|
2
1
|
require 'date'
|
3
2
|
# Copyright 2006-2015
|
4
3
|
# @author Kevin C. Olbrich, Ph.D.
|
@@ -62,7 +61,7 @@ module RubyUnits
|
|
62
61
|
RANKINE = ['<rankine>'].freeze
|
63
62
|
CELSIUS = ['<celsius>'].freeze
|
64
63
|
@@temp_regex = nil
|
65
|
-
SIGNATURE_VECTOR = %i
|
64
|
+
SIGNATURE_VECTOR = %i[
|
66
65
|
length
|
67
66
|
time
|
68
67
|
temperature
|
@@ -73,7 +72,7 @@ module RubyUnits
|
|
73
72
|
currency
|
74
73
|
information
|
75
74
|
angle
|
76
|
-
|
75
|
+
].freeze
|
77
76
|
@@kinds = {
|
78
77
|
-312_078 => :elastance,
|
79
78
|
-312_058 => :resistance,
|
@@ -333,9 +332,9 @@ module RubyUnits
|
|
333
332
|
when rational
|
334
333
|
# if it has whitespace, it will be of the form '6 1/2'
|
335
334
|
if num =~ RATIONAL_NUMBER
|
336
|
-
sign =
|
337
|
-
n =
|
338
|
-
f = Rational(
|
335
|
+
sign = Regexp.last_match(1) == '-' ? -1 : 1
|
336
|
+
n = Regexp.last_match(2).to_i
|
337
|
+
f = Rational(Regexp.last_match(3).to_i, Regexp.last_match(4).to_i)
|
339
338
|
sign * (n + f)
|
340
339
|
else
|
341
340
|
Rational(*num.split('/').map(&:to_i))
|
@@ -369,7 +368,7 @@ module RubyUnits
|
|
369
368
|
|
370
369
|
def self.temp_regex
|
371
370
|
@@temp_regex ||= begin
|
372
|
-
temp_units = %w
|
371
|
+
temp_units = %w[tempK tempC tempF tempR degK degC degF degR]
|
373
372
|
aliases = temp_units.map do |unit|
|
374
373
|
d = RubyUnits::Unit.definition(unit)
|
375
374
|
d && d.aliases
|
@@ -436,7 +435,11 @@ module RubyUnits
|
|
436
435
|
@base = from.base?
|
437
436
|
@signature = from.signature
|
438
437
|
@base_scalar = from.base_scalar
|
439
|
-
@unit_name =
|
438
|
+
@unit_name = begin
|
439
|
+
from.unit_name
|
440
|
+
rescue
|
441
|
+
nil
|
442
|
+
end
|
440
443
|
self
|
441
444
|
end
|
442
445
|
|
@@ -474,7 +477,11 @@ module RubyUnits
|
|
474
477
|
cached = @@cached_units[options[1]] * options[0]
|
475
478
|
copy(cached)
|
476
479
|
rescue
|
477
|
-
initialize("#{options[0]} #{(
|
480
|
+
initialize("#{options[0]} #{(begin
|
481
|
+
options[1].units
|
482
|
+
rescue
|
483
|
+
options[1]
|
484
|
+
end)}")
|
478
485
|
end
|
479
486
|
return
|
480
487
|
end
|
@@ -495,7 +502,7 @@ module RubyUnits
|
|
495
502
|
copy(options[0])
|
496
503
|
return
|
497
504
|
when Hash
|
498
|
-
@scalar = options[0][:scalar] || 1
|
505
|
+
@scalar = (options[0][:scalar] || 1)
|
499
506
|
@numerator = options[0][:numerator] || UNITY_ARRAY
|
500
507
|
@denominator = options[0][:denominator] || UNITY_ARRAY
|
501
508
|
@signature = options[0][:signature]
|
@@ -582,7 +589,11 @@ module RubyUnits
|
|
582
589
|
return base
|
583
590
|
end
|
584
591
|
|
585
|
-
cached = (
|
592
|
+
cached = (begin
|
593
|
+
(@@base_unit_cache[units] * scalar)
|
594
|
+
rescue
|
595
|
+
nil
|
596
|
+
end)
|
586
597
|
return cached if cached
|
587
598
|
|
588
599
|
num = []
|
@@ -630,6 +641,7 @@ module RubyUnits
|
|
630
641
|
#
|
631
642
|
# output is cached so subsequent calls for the same format will be fast
|
632
643
|
#
|
644
|
+
# @note Rational scalars that are equal to an integer will be represented as integers (i.e, 6/1 => 6, 4/2 => 2, etc..)
|
633
645
|
# @param [Symbol] target_units
|
634
646
|
# @return [String]
|
635
647
|
def to_s(target_units = nil)
|
@@ -652,23 +664,25 @@ module RubyUnits
|
|
652
664
|
''
|
653
665
|
when /(%[\-+\.\w#]+)\s*(.+)*/ # format string like '%0.2f in'
|
654
666
|
begin
|
655
|
-
if
|
656
|
-
convert_to(
|
667
|
+
if Regexp.last_match(2) # unit specified, need to convert
|
668
|
+
convert_to(Regexp.last_match(2)).to_s(Regexp.last_match(1))
|
657
669
|
else
|
658
|
-
"#{
|
670
|
+
"#{Regexp.last_match(1) % @scalar}#{separator}#{Regexp.last_match(2) || units}".strip
|
659
671
|
end
|
660
672
|
rescue # parse it like a strftime format string
|
661
673
|
(DateTime.new(0) + self).strftime(target_units)
|
662
674
|
end
|
663
675
|
when /(\S+)/ # unit only 'mm' or '1/mm'
|
664
|
-
convert_to(
|
676
|
+
convert_to(Regexp.last_match(1)).to_s
|
665
677
|
else
|
666
678
|
raise 'unhandled case'
|
667
679
|
end
|
668
680
|
else
|
669
681
|
out = case @scalar
|
670
|
-
when
|
682
|
+
when Complex
|
671
683
|
"#{@scalar}#{separator}#{units}"
|
684
|
+
when Rational
|
685
|
+
"#{@scalar == @scalar.to_i ? @scalar.to_i : @scalar}#{separator}#{units}"
|
672
686
|
else
|
673
687
|
"#{'%g' % @scalar}#{separator}#{units}"
|
674
688
|
end.strip
|
@@ -833,7 +847,13 @@ module RubyUnits
|
|
833
847
|
RubyUnits::Unit.new(scalar: (other.scalar + convert_to(other.temperature_scale).scalar), numerator: other.numerator, denominator: other.denominator, signature: other.signature)
|
834
848
|
end
|
835
849
|
else
|
836
|
-
@q ||=
|
850
|
+
@q ||= begin
|
851
|
+
begin
|
852
|
+
Rational(@@cached_units[units].scalar, @@cached_units[units].base_scalar)
|
853
|
+
rescue
|
854
|
+
units.to_unit.to_base.scalar
|
855
|
+
end
|
856
|
+
end
|
837
857
|
RubyUnits::Unit.new(scalar: (base_scalar + other.base_scalar) * @q, numerator: @numerator, denominator: @denominator, signature: @signature)
|
838
858
|
end
|
839
859
|
else
|
@@ -870,7 +890,13 @@ module RubyUnits
|
|
870
890
|
elsif other.temperature?
|
871
891
|
raise ArgumentError, 'Cannot subtract a temperature from a differential degree unit'
|
872
892
|
else
|
873
|
-
@q ||=
|
893
|
+
@q ||= begin
|
894
|
+
begin
|
895
|
+
Rational(@@cached_units[units].scalar, @@cached_units[units].base_scalar)
|
896
|
+
rescue
|
897
|
+
Rational(units.to_unit.scalar, units.to_unit.to_base.scalar)
|
898
|
+
end
|
899
|
+
end
|
874
900
|
RubyUnits::Unit.new(scalar: (base_scalar - other.base_scalar) * @q, numerator: @numerator, denominator: @denominator, signature: @signature)
|
875
901
|
end
|
876
902
|
else
|
@@ -1067,9 +1093,12 @@ module RubyUnits
|
|
1067
1093
|
if (Unit === other && other.temperature?) || (String === other && other =~ /temp[CFRK]/)
|
1068
1094
|
raise ArgumentError, 'Receiver is not a temperature unit' unless degree?
|
1069
1095
|
start_unit = units
|
1070
|
-
target_unit =
|
1071
|
-
|
1072
|
-
|
1096
|
+
target_unit = begin
|
1097
|
+
other.units
|
1098
|
+
rescue
|
1099
|
+
other
|
1100
|
+
end
|
1101
|
+
@base_scalar ||= case @@unit_map[start_unit]
|
1073
1102
|
when '<tempC>'
|
1074
1103
|
@scalar + 273.15
|
1075
1104
|
when '<tempK>'
|
@@ -1079,7 +1108,6 @@ module RubyUnits
|
|
1079
1108
|
when '<tempR>'
|
1080
1109
|
@scalar * Rational(5, 9)
|
1081
1110
|
end
|
1082
|
-
end
|
1083
1111
|
q = case @@unit_map[target_unit]
|
1084
1112
|
when '<tempC>'
|
1085
1113
|
@base_scalar - 273.15
|
@@ -1312,7 +1340,11 @@ module RubyUnits
|
|
1312
1340
|
def before(time_point = ::Time.now)
|
1313
1341
|
case time_point
|
1314
1342
|
when Time, Date, DateTime
|
1315
|
-
return (
|
1343
|
+
return (begin
|
1344
|
+
time_point - self
|
1345
|
+
rescue
|
1346
|
+
time_point.to_datetime - self
|
1347
|
+
end)
|
1316
1348
|
else
|
1317
1349
|
raise ArgumentError, 'Must specify a Time, Date, or DateTime'
|
1318
1350
|
end
|
@@ -1356,7 +1388,11 @@ module RubyUnits
|
|
1356
1388
|
def from(time_point)
|
1357
1389
|
case time_point
|
1358
1390
|
when Time, DateTime, Date
|
1359
|
-
(
|
1391
|
+
(begin
|
1392
|
+
time_point + self
|
1393
|
+
rescue
|
1394
|
+
time_point.to_datetime + self
|
1395
|
+
end)
|
1360
1396
|
else
|
1361
1397
|
raise ArgumentError, 'Must specify a Time, Date, or DateTime'
|
1362
1398
|
end
|
@@ -1478,7 +1514,7 @@ module RubyUnits
|
|
1478
1514
|
# @todo This should either be a separate class or at least a class method
|
1479
1515
|
def parse(passed_unit_string = '0')
|
1480
1516
|
unit_string = passed_unit_string.dup
|
1481
|
-
unit_string = "#{
|
1517
|
+
unit_string = "#{Regexp.last_match(1)} USD" if unit_string =~ /\$\s*(#{NUMBER_REGEX})/
|
1482
1518
|
unit_string.gsub!("\u00b0".force_encoding('utf-8'), 'deg') if unit_string.encoding == Encoding::UTF_8
|
1483
1519
|
|
1484
1520
|
unit_string.gsub!(/[%'"#]/, '%' => 'percent', "'" => 'feet', '"' => 'inch', '#' => 'pound')
|
@@ -1500,8 +1536,12 @@ module RubyUnits
|
|
1500
1536
|
end
|
1501
1537
|
|
1502
1538
|
unit_string =~ NUMBER_REGEX
|
1503
|
-
unit = @@cached_units[
|
1504
|
-
mult =
|
1539
|
+
unit = @@cached_units[Regexp.last_match(2)]
|
1540
|
+
mult = begin
|
1541
|
+
(Regexp.last_match(1).empty? ? 1.0 : Regexp.last_match(1).to_f)
|
1542
|
+
rescue
|
1543
|
+
1.0
|
1544
|
+
end
|
1505
1545
|
mult = mult.to_int if mult.to_int == mult
|
1506
1546
|
if unit
|
1507
1547
|
copy(unit)
|
@@ -1567,7 +1607,7 @@ module RubyUnits
|
|
1567
1607
|
end
|
1568
1608
|
end
|
1569
1609
|
if bottom
|
1570
|
-
bottom.gsub!(BOTTOM_REGEX) { "#{
|
1610
|
+
bottom.gsub!(BOTTOM_REGEX) { "#{Regexp.last_match(1)} " * Regexp.last_match(2).to_i }
|
1571
1611
|
# Separate leading decimal from denominator, if any
|
1572
1612
|
bottom_scalar, bottom = bottom.scan(NUMBER_UNIT_REGEX)[0]
|
1573
1613
|
end
|
@@ -3,98 +3,98 @@ RubyUnits::Unit.new('1')
|
|
3
3
|
|
4
4
|
RubyUnits::Unit.define('meter') do |unit|
|
5
5
|
unit.scalar = 1
|
6
|
-
unit.numerator = %w
|
7
|
-
unit.aliases = %w
|
6
|
+
unit.numerator = %w[<meter>]
|
7
|
+
unit.aliases = %w[m meter meters metre metres]
|
8
8
|
unit.kind = :length
|
9
9
|
end
|
10
10
|
|
11
11
|
RubyUnits::Unit.define('kilogram') do |unit|
|
12
12
|
unit.scalar = 1
|
13
|
-
unit.numerator = %w
|
14
|
-
unit.aliases = %w
|
13
|
+
unit.numerator = %w[<kilogram>]
|
14
|
+
unit.aliases = %w[kg kilogram kilograms]
|
15
15
|
unit.kind = :mass
|
16
16
|
end
|
17
17
|
|
18
18
|
RubyUnits::Unit.define('second') do |unit|
|
19
19
|
unit.scalar = 1
|
20
|
-
unit.numerator = %w
|
21
|
-
unit.aliases = %w
|
20
|
+
unit.numerator = %w[<second>]
|
21
|
+
unit.aliases = %w[s sec second seconds]
|
22
22
|
unit.kind = :time
|
23
23
|
end
|
24
24
|
|
25
25
|
RubyUnits::Unit.define('mole') do |unit|
|
26
26
|
unit.scalar = 1
|
27
|
-
unit.numerator = %w
|
28
|
-
unit.aliases = %w
|
27
|
+
unit.numerator = %w[<mole>]
|
28
|
+
unit.aliases = %w[mol mole]
|
29
29
|
unit.kind = :substance
|
30
30
|
end
|
31
31
|
|
32
32
|
RubyUnits::Unit.define('ampere') do |unit|
|
33
33
|
unit.scalar = 1
|
34
|
-
unit.numerator = %w
|
35
|
-
unit.aliases = %w
|
34
|
+
unit.numerator = %w[<ampere>]
|
35
|
+
unit.aliases = %w[A ampere amperes amp amps]
|
36
36
|
unit.kind = :current
|
37
37
|
end
|
38
38
|
|
39
39
|
RubyUnits::Unit.define('radian') do |unit|
|
40
40
|
unit.scalar = 1
|
41
|
-
unit.numerator = %w
|
42
|
-
unit.aliases = %w
|
41
|
+
unit.numerator = %w[<radian>]
|
42
|
+
unit.aliases = %w[rad radian radians]
|
43
43
|
unit.kind = :angle
|
44
44
|
end
|
45
45
|
|
46
46
|
RubyUnits::Unit.define('kelvin') do |unit|
|
47
47
|
unit.scalar = 1
|
48
|
-
unit.numerator = %w
|
49
|
-
unit.aliases = %w
|
48
|
+
unit.numerator = %w[<kelvin>]
|
49
|
+
unit.aliases = %w[degK kelvin]
|
50
50
|
unit.kind = :temperature
|
51
51
|
end
|
52
52
|
|
53
53
|
RubyUnits::Unit.define('tempK') do |unit|
|
54
54
|
unit.scalar = 1
|
55
|
-
unit.numerator = %w
|
56
|
-
unit.aliases = %w
|
55
|
+
unit.numerator = %w[<tempK>]
|
56
|
+
unit.aliases = %w[tempK]
|
57
57
|
unit.kind = :temperature
|
58
58
|
end
|
59
59
|
|
60
60
|
RubyUnits::Unit.define('byte') do |unit|
|
61
61
|
unit.scalar = 1
|
62
|
-
unit.numerator = %w
|
63
|
-
unit.aliases = %w
|
62
|
+
unit.numerator = %w[<byte>]
|
63
|
+
unit.aliases = %w[B byte bytes]
|
64
64
|
unit.kind = :information
|
65
65
|
end
|
66
66
|
|
67
67
|
RubyUnits::Unit.define('dollar') do |unit|
|
68
68
|
unit.scalar = 1
|
69
|
-
unit.numerator = %w
|
70
|
-
unit.aliases = %w
|
69
|
+
unit.numerator = %w[<dollar>]
|
70
|
+
unit.aliases = %w[USD dollar]
|
71
71
|
unit.kind = :currency
|
72
72
|
end
|
73
73
|
|
74
74
|
RubyUnits::Unit.define('candela') do |unit|
|
75
75
|
unit.scalar = 1
|
76
|
-
unit.numerator = %w
|
77
|
-
unit.aliases = %w
|
76
|
+
unit.numerator = %w[<candela>]
|
77
|
+
unit.aliases = %w[cd candela]
|
78
78
|
unit.kind = :luminosity
|
79
79
|
end
|
80
80
|
|
81
81
|
RubyUnits::Unit.define('each') do |unit|
|
82
82
|
unit.scalar = 1
|
83
|
-
unit.numerator = %w
|
84
|
-
unit.aliases = %w
|
83
|
+
unit.numerator = %w[<each>]
|
84
|
+
unit.aliases = %w[each]
|
85
85
|
unit.kind = :counting
|
86
86
|
end
|
87
87
|
|
88
88
|
RubyUnits::Unit.define('steradian') do |unit|
|
89
89
|
unit.scalar = 1
|
90
|
-
unit.numerator = %w
|
91
|
-
unit.aliases = %w
|
90
|
+
unit.numerator = %w[<steradian>]
|
91
|
+
unit.aliases = %w[sr steradian steradians]
|
92
92
|
unit.kind = :solid_angle
|
93
93
|
end
|
94
94
|
|
95
95
|
RubyUnits::Unit.define('decibel') do |unit|
|
96
96
|
unit.scalar = 1
|
97
|
-
unit.numerator = %w
|
98
|
-
unit.aliases = %w
|
97
|
+
unit.numerator = %w[<decibel>]
|
98
|
+
unit.aliases = %w[dB decibel decibels]
|
99
99
|
unit.kind = :logarithmic
|
100
100
|
end
|
@@ -1,36 +1,34 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
1
|
{
|
4
|
-
'googol' => [%w
|
5
|
-
'yobi' => [%w
|
6
|
-
'zebi' => [%w
|
7
|
-
'exbi' => [%w
|
8
|
-
'pebi' => [%w
|
9
|
-
'tebi' => [%w
|
10
|
-
'gibi' => [%w
|
11
|
-
'mebi' => [%w
|
12
|
-
'kibi' => [%w
|
13
|
-
'yotta' => [%w
|
14
|
-
'zetta' => [%w
|
15
|
-
'exa' => [%w
|
16
|
-
'peta' => [%w
|
17
|
-
'tera' => [%w
|
18
|
-
'giga' => [%w
|
19
|
-
'mega' => [%w
|
20
|
-
'kilo' => [%w
|
21
|
-
'hecto' => [%w
|
22
|
-
'deca' => [%w
|
23
|
-
'1' => [%w
|
24
|
-
'deci' => [%w
|
25
|
-
'centi' => [%w
|
26
|
-
'milli' => [%w
|
27
|
-
'micro' => [%w
|
28
|
-
'nano' => [%w
|
29
|
-
'pico' => [%w
|
30
|
-
'femto' => [%w
|
31
|
-
'atto' => [%w
|
32
|
-
'zepto' => [%w
|
33
|
-
'yocto' => [%w
|
2
|
+
'googol' => [%w[googol], 1e100],
|
3
|
+
'yobi' => [%w[Yi Yobi yobi], 2**80],
|
4
|
+
'zebi' => [%w[Zi Zebi zebi], 2**70],
|
5
|
+
'exbi' => [%w[Ei Exbi exbi], 2**60],
|
6
|
+
'pebi' => [%w[Pi Pebi pebi], 2**50],
|
7
|
+
'tebi' => [%w[Ti Tebi tebi], 2**40],
|
8
|
+
'gibi' => [%w[Gi Gibi gibi], 2**30],
|
9
|
+
'mebi' => [%w[Mi Mebi mebi], 2**20],
|
10
|
+
'kibi' => [%w[Ki Kibi kibi], 2**10],
|
11
|
+
'yotta' => [%w[Y Yotta yotta], 1e24],
|
12
|
+
'zetta' => [%w[Z Zetta zetta], 1e21],
|
13
|
+
'exa' => [%w[E Exa exa], 1e18],
|
14
|
+
'peta' => [%w[P Peta peta], 1e15],
|
15
|
+
'tera' => [%w[T Tera tera], 1e12],
|
16
|
+
'giga' => [%w[G Giga giga], 1e9],
|
17
|
+
'mega' => [%w[M Mega mega], 1e6],
|
18
|
+
'kilo' => [%w[k kilo], 1e3],
|
19
|
+
'hecto' => [%w[h Hecto hecto], 1e2],
|
20
|
+
'deca' => [%w[da Deca deca deka], 1e1],
|
21
|
+
'1' => [%w[1], 1],
|
22
|
+
'deci' => [%w[d Deci deci], Rational(1, 1e1)],
|
23
|
+
'centi' => [%w[c Centi centi], Rational(1, 1e2)],
|
24
|
+
'milli' => [%w[m Milli milli], Rational(1, 1e3)],
|
25
|
+
'micro' => [%w[u µ Micro micro mc], Rational(1, 1e6)],
|
26
|
+
'nano' => [%w[n Nano nano], Rational(1, 1e9)],
|
27
|
+
'pico' => [%w[p Pico pico], Rational(1, 1e12)],
|
28
|
+
'femto' => [%w[f Femto femto], Rational(1, 1e15)],
|
29
|
+
'atto' => [%w[a Atto atto], Rational(1, 1e18)],
|
30
|
+
'zepto' => [%w[z Zepto zepto], Rational(1, 1e21)],
|
31
|
+
'yocto' => [%w[y Yocto yocto], Rational(1, 1e24)]
|
34
32
|
}.each do |name, definition|
|
35
33
|
RubyUnits::Unit.define(name) do |unit|
|
36
34
|
aliases, scalar = definition
|