ruby-units 2.1.0 → 2.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.codeclimate.yml +32 -0
- data/.csslintrc +2 -0
- data/.eslintignore +1 -0
- data/.eslintrc +213 -0
- data/.github/workflows/tests.yml +40 -0
- data/.gitignore +11 -0
- data/.rspec +2 -0
- data/.rubocop.yml +24 -0
- data/.ruby-version +1 -0
- data/.solargraph.yml +16 -0
- data/CHANGELOG.txt +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +164 -0
- data/Guardfile +31 -0
- data/LICENSE.txt +18 -17
- data/README.md +124 -99
- data/Rakefile +3 -24
- data/lib/ruby_units/date.rb +2 -2
- data/lib/ruby_units/math.rb +1 -3
- data/lib/ruby_units/time.rb +2 -2
- data/lib/ruby_units/unit.rb +83 -54
- 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/lib/ruby_units/version.rb +1 -4
- data/ruby-units.gemspec +35 -72
- metadata +121 -24
- data/VERSION +0 -1
data/Rakefile
CHANGED
|
@@ -1,27 +1,6 @@
|
|
|
1
|
-
require '
|
|
2
|
-
require 'rake'
|
|
3
|
-
require 'rake/testtask'
|
|
4
|
-
require './lib/ruby-units'
|
|
5
|
-
|
|
6
|
-
begin
|
|
7
|
-
require 'jeweler'
|
|
8
|
-
Jeweler::Tasks.new do |gem|
|
|
9
|
-
gem.name = 'ruby-units'
|
|
10
|
-
gem.summary = 'A class that performs unit conversions and unit math'
|
|
11
|
-
gem.description = 'Provides classes and methods to perform unit math and conversions'
|
|
12
|
-
gem.authors = ['Kevin Olbrich, Ph.D.']
|
|
13
|
-
gem.email = ['kevin.olbrich+ruby_units@gmail.com']
|
|
14
|
-
gem.homepage = 'https://github.com/olbrich/ruby-units'
|
|
15
|
-
gem.files.exclude('.*', 'test/**/*', 'spec/**/*', 'Gemfile', 'Guardfile')
|
|
16
|
-
gem.license = 'MIT'
|
|
17
|
-
end
|
|
18
|
-
Jeweler::GemcutterTasks.new
|
|
19
|
-
rescue LoadError
|
|
20
|
-
puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
|
|
21
|
-
end
|
|
22
|
-
|
|
1
|
+
require 'bundler/gem_tasks'
|
|
23
2
|
require 'rspec/core/rake_task'
|
|
24
|
-
|
|
25
|
-
RSpec::Core::RakeTask.new
|
|
3
|
+
|
|
4
|
+
RSpec::Core::RakeTask.new(:spec)
|
|
26
5
|
|
|
27
6
|
task default: :spec
|
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/math.rb
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
require 'mathn'
|
|
2
|
-
|
|
3
1
|
# Math will convert unit objects to radians and then attempt to use the value for
|
|
4
2
|
# trigonometric functions.
|
|
5
3
|
module Math
|
|
@@ -100,7 +98,7 @@ module Math
|
|
|
100
98
|
# @return [Numeric]
|
|
101
99
|
def hypot(x, y)
|
|
102
100
|
if RubyUnits::Unit === x && RubyUnits::Unit === y
|
|
103
|
-
(x**2 + y**2)**(1
|
|
101
|
+
(x**2 + y**2)**Rational(1, 2)
|
|
104
102
|
else
|
|
105
103
|
unit_hypot(x, y)
|
|
106
104
|
end
|
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.
|
|
@@ -23,7 +22,6 @@ require 'date'
|
|
|
23
22
|
#
|
|
24
23
|
module RubyUnits
|
|
25
24
|
class Unit < Numeric
|
|
26
|
-
VERSION = Unit::Version::STRING
|
|
27
25
|
@@definitions = {}
|
|
28
26
|
@@prefix_values = {}
|
|
29
27
|
@@prefix_map = {}
|
|
@@ -62,7 +60,7 @@ module RubyUnits
|
|
|
62
60
|
RANKINE = ['<rankine>'].freeze
|
|
63
61
|
CELSIUS = ['<celsius>'].freeze
|
|
64
62
|
@@temp_regex = nil
|
|
65
|
-
SIGNATURE_VECTOR = %i
|
|
63
|
+
SIGNATURE_VECTOR = %i[
|
|
66
64
|
length
|
|
67
65
|
time
|
|
68
66
|
temperature
|
|
@@ -73,7 +71,7 @@ module RubyUnits
|
|
|
73
71
|
currency
|
|
74
72
|
information
|
|
75
73
|
angle
|
|
76
|
-
|
|
74
|
+
].freeze
|
|
77
75
|
@@kinds = {
|
|
78
76
|
-312_078 => :elastance,
|
|
79
77
|
-312_058 => :resistance,
|
|
@@ -333,9 +331,9 @@ module RubyUnits
|
|
|
333
331
|
when rational
|
|
334
332
|
# if it has whitespace, it will be of the form '6 1/2'
|
|
335
333
|
if num =~ RATIONAL_NUMBER
|
|
336
|
-
sign =
|
|
337
|
-
n =
|
|
338
|
-
f = Rational(
|
|
334
|
+
sign = Regexp.last_match(1) == '-' ? -1 : 1
|
|
335
|
+
n = Regexp.last_match(2).to_i
|
|
336
|
+
f = Rational(Regexp.last_match(3).to_i, Regexp.last_match(4).to_i)
|
|
339
337
|
sign * (n + f)
|
|
340
338
|
else
|
|
341
339
|
Rational(*num.split('/').map(&:to_i))
|
|
@@ -369,7 +367,7 @@ module RubyUnits
|
|
|
369
367
|
|
|
370
368
|
def self.temp_regex
|
|
371
369
|
@@temp_regex ||= begin
|
|
372
|
-
temp_units = %w
|
|
370
|
+
temp_units = %w[tempK tempC tempF tempR degK degC degF degR]
|
|
373
371
|
aliases = temp_units.map do |unit|
|
|
374
372
|
d = RubyUnits::Unit.definition(unit)
|
|
375
373
|
d && d.aliases
|
|
@@ -436,7 +434,11 @@ module RubyUnits
|
|
|
436
434
|
@base = from.base?
|
|
437
435
|
@signature = from.signature
|
|
438
436
|
@base_scalar = from.base_scalar
|
|
439
|
-
@unit_name =
|
|
437
|
+
@unit_name = begin
|
|
438
|
+
from.unit_name
|
|
439
|
+
rescue
|
|
440
|
+
nil
|
|
441
|
+
end
|
|
440
442
|
self
|
|
441
443
|
end
|
|
442
444
|
|
|
@@ -474,7 +476,11 @@ module RubyUnits
|
|
|
474
476
|
cached = @@cached_units[options[1]] * options[0]
|
|
475
477
|
copy(cached)
|
|
476
478
|
rescue
|
|
477
|
-
initialize("#{options[0]} #{(
|
|
479
|
+
initialize("#{options[0]} #{(begin
|
|
480
|
+
options[1].units
|
|
481
|
+
rescue
|
|
482
|
+
options[1]
|
|
483
|
+
end)}")
|
|
478
484
|
end
|
|
479
485
|
return
|
|
480
486
|
end
|
|
@@ -495,7 +501,7 @@ module RubyUnits
|
|
|
495
501
|
copy(options[0])
|
|
496
502
|
return
|
|
497
503
|
when Hash
|
|
498
|
-
@scalar = options[0][:scalar] || 1
|
|
504
|
+
@scalar = (options[0][:scalar] || 1)
|
|
499
505
|
@numerator = options[0][:numerator] || UNITY_ARRAY
|
|
500
506
|
@denominator = options[0][:denominator] || UNITY_ARRAY
|
|
501
507
|
@signature = options[0][:signature]
|
|
@@ -582,28 +588,32 @@ module RubyUnits
|
|
|
582
588
|
return base
|
|
583
589
|
end
|
|
584
590
|
|
|
585
|
-
cached = (
|
|
591
|
+
cached = (begin
|
|
592
|
+
(@@base_unit_cache[units] * scalar)
|
|
593
|
+
rescue
|
|
594
|
+
nil
|
|
595
|
+
end)
|
|
586
596
|
return cached if cached
|
|
587
597
|
|
|
588
598
|
num = []
|
|
589
599
|
den = []
|
|
590
|
-
q = 1
|
|
591
|
-
@numerator.compact.each do |
|
|
592
|
-
if @@prefix_values[
|
|
593
|
-
q *= @@prefix_values[
|
|
600
|
+
q = Rational(1)
|
|
601
|
+
@numerator.compact.each do |num_unit|
|
|
602
|
+
if @@prefix_values[num_unit]
|
|
603
|
+
q *= @@prefix_values[num_unit]
|
|
594
604
|
else
|
|
595
|
-
q *= @@unit_values[
|
|
596
|
-
num << @@unit_values[
|
|
597
|
-
den << @@unit_values[
|
|
605
|
+
q *= @@unit_values[num_unit][:scalar] if @@unit_values[num_unit]
|
|
606
|
+
num << @@unit_values[num_unit][:numerator] if @@unit_values[num_unit] && @@unit_values[num_unit][:numerator]
|
|
607
|
+
den << @@unit_values[num_unit][:denominator] if @@unit_values[num_unit] && @@unit_values[num_unit][:denominator]
|
|
598
608
|
end
|
|
599
609
|
end
|
|
600
|
-
@denominator.compact.each do |
|
|
601
|
-
if @@prefix_values[
|
|
602
|
-
q /= @@prefix_values[
|
|
610
|
+
@denominator.compact.each do |num_unit|
|
|
611
|
+
if @@prefix_values[num_unit]
|
|
612
|
+
q /= @@prefix_values[num_unit]
|
|
603
613
|
else
|
|
604
|
-
q /= @@unit_values[
|
|
605
|
-
den << @@unit_values[
|
|
606
|
-
num << @@unit_values[
|
|
614
|
+
q /= @@unit_values[num_unit][:scalar] if @@unit_values[num_unit]
|
|
615
|
+
den << @@unit_values[num_unit][:numerator] if @@unit_values[num_unit] && @@unit_values[num_unit][:numerator]
|
|
616
|
+
num << @@unit_values[num_unit][:denominator] if @@unit_values[num_unit] && @@unit_values[num_unit][:denominator]
|
|
607
617
|
end
|
|
608
618
|
end
|
|
609
619
|
|
|
@@ -630,6 +640,7 @@ module RubyUnits
|
|
|
630
640
|
#
|
|
631
641
|
# output is cached so subsequent calls for the same format will be fast
|
|
632
642
|
#
|
|
643
|
+
# @note Rational scalars that are equal to an integer will be represented as integers (i.e, 6/1 => 6, 4/2 => 2, etc..)
|
|
633
644
|
# @param [Symbol] target_units
|
|
634
645
|
# @return [String]
|
|
635
646
|
def to_s(target_units = nil)
|
|
@@ -652,23 +663,25 @@ module RubyUnits
|
|
|
652
663
|
''
|
|
653
664
|
when /(%[\-+\.\w#]+)\s*(.+)*/ # format string like '%0.2f in'
|
|
654
665
|
begin
|
|
655
|
-
if
|
|
656
|
-
convert_to(
|
|
666
|
+
if Regexp.last_match(2) # unit specified, need to convert
|
|
667
|
+
convert_to(Regexp.last_match(2)).to_s(Regexp.last_match(1))
|
|
657
668
|
else
|
|
658
|
-
"#{
|
|
669
|
+
"#{Regexp.last_match(1) % @scalar}#{separator}#{Regexp.last_match(2) || units}".strip
|
|
659
670
|
end
|
|
660
671
|
rescue # parse it like a strftime format string
|
|
661
672
|
(DateTime.new(0) + self).strftime(target_units)
|
|
662
673
|
end
|
|
663
674
|
when /(\S+)/ # unit only 'mm' or '1/mm'
|
|
664
|
-
convert_to(
|
|
675
|
+
convert_to(Regexp.last_match(1)).to_s
|
|
665
676
|
else
|
|
666
677
|
raise 'unhandled case'
|
|
667
678
|
end
|
|
668
679
|
else
|
|
669
680
|
out = case @scalar
|
|
670
|
-
when
|
|
681
|
+
when Complex
|
|
671
682
|
"#{@scalar}#{separator}#{units}"
|
|
683
|
+
when Rational
|
|
684
|
+
"#{@scalar == @scalar.to_i ? @scalar.to_i : @scalar}#{separator}#{units}"
|
|
672
685
|
else
|
|
673
686
|
"#{'%g' % @scalar}#{separator}#{units}"
|
|
674
687
|
end.strip
|
|
@@ -833,8 +846,7 @@ module RubyUnits
|
|
|
833
846
|
RubyUnits::Unit.new(scalar: (other.scalar + convert_to(other.temperature_scale).scalar), numerator: other.numerator, denominator: other.denominator, signature: other.signature)
|
|
834
847
|
end
|
|
835
848
|
else
|
|
836
|
-
|
|
837
|
-
RubyUnits::Unit.new(scalar: (base_scalar + other.base_scalar) * @q, numerator: @numerator, denominator: @denominator, signature: @signature)
|
|
849
|
+
RubyUnits::Unit.new(scalar: (base_scalar + other.base_scalar), numerator: base.numerator, denominator: base.denominator, signature: @signature).convert_to(self)
|
|
838
850
|
end
|
|
839
851
|
else
|
|
840
852
|
raise ArgumentError, "Incompatible Units ('#{self}' not compatible with '#{other}')"
|
|
@@ -870,8 +882,7 @@ module RubyUnits
|
|
|
870
882
|
elsif other.temperature?
|
|
871
883
|
raise ArgumentError, 'Cannot subtract a temperature from a differential degree unit'
|
|
872
884
|
else
|
|
873
|
-
|
|
874
|
-
RubyUnits::Unit.new(scalar: (base_scalar - other.base_scalar) * @q, numerator: @numerator, denominator: @denominator, signature: @signature)
|
|
885
|
+
RubyUnits::Unit.new(scalar: (base_scalar - other.base_scalar), numerator: base.numerator, denominator: base.denominator, signature: @signature).convert_to(self)
|
|
875
886
|
end
|
|
876
887
|
else
|
|
877
888
|
raise ArgumentError, "Incompatible Units ('#{self}' not compatible with '#{other}')"
|
|
@@ -914,12 +925,16 @@ module RubyUnits
|
|
|
914
925
|
when Unit
|
|
915
926
|
raise ZeroDivisionError if other.zero?
|
|
916
927
|
raise ArgumentError, 'Cannot divide with temperatures' if [other, self].any?(&:temperature?)
|
|
917
|
-
|
|
928
|
+
sc = Rational(@scalar, other.scalar)
|
|
929
|
+
sc = sc.numerator if sc.denominator == 1
|
|
930
|
+
opts = RubyUnits::Unit.eliminate_terms(sc, @numerator + other.denominator, @denominator + other.numerator)
|
|
918
931
|
opts[:signature] = @signature - other.signature
|
|
919
932
|
RubyUnits::Unit.new(opts)
|
|
920
933
|
when Numeric
|
|
921
934
|
raise ZeroDivisionError if other.zero?
|
|
922
|
-
|
|
935
|
+
sc = Rational(@scalar, other)
|
|
936
|
+
sc = sc.numerator if sc.denominator == 1
|
|
937
|
+
RubyUnits::Unit.new(scalar: sc, numerator: @numerator, denominator: @denominator, signature: @signature)
|
|
923
938
|
else
|
|
924
939
|
x, y = coerce(other)
|
|
925
940
|
y / x
|
|
@@ -972,11 +987,11 @@ module RubyUnits
|
|
|
972
987
|
return power(other)
|
|
973
988
|
when Float
|
|
974
989
|
return self**other.to_i if other == other.to_i
|
|
975
|
-
valid = (1..9).map { |
|
|
990
|
+
valid = (1..9).map { |n| Rational(1, n) }
|
|
976
991
|
raise ArgumentError, 'Not a n-th root (1..9), use 1/n' unless valid.include? other.abs
|
|
977
|
-
return root((1
|
|
992
|
+
return root(Rational(1, other).to_int)
|
|
978
993
|
when Complex
|
|
979
|
-
raise ArgumentError, 'exponentiation of complex numbers is not
|
|
994
|
+
raise ArgumentError, 'exponentiation of complex numbers is not supported.'
|
|
980
995
|
else
|
|
981
996
|
raise ArgumentError, 'Invalid Exponent'
|
|
982
997
|
end
|
|
@@ -1063,28 +1078,30 @@ module RubyUnits
|
|
|
1063
1078
|
if (Unit === other && other.temperature?) || (String === other && other =~ /temp[CFRK]/)
|
|
1064
1079
|
raise ArgumentError, 'Receiver is not a temperature unit' unless degree?
|
|
1065
1080
|
start_unit = units
|
|
1066
|
-
target_unit =
|
|
1067
|
-
|
|
1068
|
-
|
|
1081
|
+
target_unit = begin
|
|
1082
|
+
other.units
|
|
1083
|
+
rescue
|
|
1084
|
+
other
|
|
1085
|
+
end
|
|
1086
|
+
@base_scalar ||= case @@unit_map[start_unit]
|
|
1069
1087
|
when '<tempC>'
|
|
1070
1088
|
@scalar + 273.15
|
|
1071
1089
|
when '<tempK>'
|
|
1072
1090
|
@scalar
|
|
1073
1091
|
when '<tempF>'
|
|
1074
|
-
(@scalar + 459.67) * Rational(5, 9)
|
|
1092
|
+
(@scalar + 459.67).to_r * Rational(5, 9)
|
|
1075
1093
|
when '<tempR>'
|
|
1076
|
-
@scalar * Rational(5, 9)
|
|
1094
|
+
@scalar.to_r * Rational(5, 9)
|
|
1077
1095
|
end
|
|
1078
|
-
end
|
|
1079
1096
|
q = case @@unit_map[target_unit]
|
|
1080
1097
|
when '<tempC>'
|
|
1081
|
-
@base_scalar - 273.
|
|
1098
|
+
@base_scalar - 273.15r
|
|
1082
1099
|
when '<tempK>'
|
|
1083
1100
|
@base_scalar
|
|
1084
1101
|
when '<tempF>'
|
|
1085
|
-
@base_scalar * Rational(9, 5) - 459.
|
|
1102
|
+
@base_scalar.to_r * Rational(9, 5) - 459.67r
|
|
1086
1103
|
when '<tempR>'
|
|
1087
|
-
@base_scalar * Rational(9, 5)
|
|
1104
|
+
@base_scalar.to_r * Rational(9, 5)
|
|
1088
1105
|
end
|
|
1089
1106
|
return RubyUnits::Unit.new("#{q} #{target_unit}")
|
|
1090
1107
|
else
|
|
@@ -1308,7 +1325,11 @@ module RubyUnits
|
|
|
1308
1325
|
def before(time_point = ::Time.now)
|
|
1309
1326
|
case time_point
|
|
1310
1327
|
when Time, Date, DateTime
|
|
1311
|
-
return (
|
|
1328
|
+
return (begin
|
|
1329
|
+
time_point - self
|
|
1330
|
+
rescue
|
|
1331
|
+
time_point.to_datetime - self
|
|
1332
|
+
end)
|
|
1312
1333
|
else
|
|
1313
1334
|
raise ArgumentError, 'Must specify a Time, Date, or DateTime'
|
|
1314
1335
|
end
|
|
@@ -1352,7 +1373,11 @@ module RubyUnits
|
|
|
1352
1373
|
def from(time_point)
|
|
1353
1374
|
case time_point
|
|
1354
1375
|
when Time, DateTime, Date
|
|
1355
|
-
(
|
|
1376
|
+
(begin
|
|
1377
|
+
time_point + self
|
|
1378
|
+
rescue
|
|
1379
|
+
time_point.to_datetime + self
|
|
1380
|
+
end)
|
|
1356
1381
|
else
|
|
1357
1382
|
raise ArgumentError, 'Must specify a Time, Date, or DateTime'
|
|
1358
1383
|
end
|
|
@@ -1474,7 +1499,7 @@ module RubyUnits
|
|
|
1474
1499
|
# @todo This should either be a separate class or at least a class method
|
|
1475
1500
|
def parse(passed_unit_string = '0')
|
|
1476
1501
|
unit_string = passed_unit_string.dup
|
|
1477
|
-
unit_string = "#{
|
|
1502
|
+
unit_string = "#{Regexp.last_match(1)} USD" if unit_string =~ /\$\s*(#{NUMBER_REGEX})/
|
|
1478
1503
|
unit_string.gsub!("\u00b0".force_encoding('utf-8'), 'deg') if unit_string.encoding == Encoding::UTF_8
|
|
1479
1504
|
|
|
1480
1505
|
unit_string.gsub!(/[%'"#]/, '%' => 'percent', "'" => 'feet', '"' => 'inch', '#' => 'pound')
|
|
@@ -1496,8 +1521,12 @@ module RubyUnits
|
|
|
1496
1521
|
end
|
|
1497
1522
|
|
|
1498
1523
|
unit_string =~ NUMBER_REGEX
|
|
1499
|
-
unit = @@cached_units[
|
|
1500
|
-
mult =
|
|
1524
|
+
unit = @@cached_units[Regexp.last_match(2)]
|
|
1525
|
+
mult = begin
|
|
1526
|
+
(Regexp.last_match(1).empty? ? 1.0 : Regexp.last_match(1).to_f)
|
|
1527
|
+
rescue
|
|
1528
|
+
1.0
|
|
1529
|
+
end
|
|
1501
1530
|
mult = mult.to_int if mult.to_int == mult
|
|
1502
1531
|
if unit
|
|
1503
1532
|
copy(unit)
|
|
@@ -1563,7 +1592,7 @@ module RubyUnits
|
|
|
1563
1592
|
end
|
|
1564
1593
|
end
|
|
1565
1594
|
if bottom
|
|
1566
|
-
bottom.gsub!(BOTTOM_REGEX) { "#{
|
|
1595
|
+
bottom.gsub!(BOTTOM_REGEX) { "#{Regexp.last_match(1)} " * Regexp.last_match(2).to_i }
|
|
1567
1596
|
# Separate leading decimal from denominator, if any
|
|
1568
1597
|
bottom_scalar, bottom = bottom.scan(NUMBER_UNIT_REGEX)[0]
|
|
1569
1598
|
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
|