sy 2.0.17 → 2.0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sy/composition.rb +26 -3
- data/lib/sy/quantity.rb +4 -0
- data/lib/sy/version.rb +1 -1
- data/lib/sy.rb +8 -6
- data/test/sy_test.rb +3 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8f9f7390d20ebd9be2e00dea57e39a1c36de4df
|
4
|
+
data.tar.gz: 91e9d5e9b85fc8789742ec150c2e7760f79f1f8d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92a5a1360619fe9473357eb3a350baa2839b6c8084c4011ccda4152f975249e60c7f7d7f02d71a3dfcbb53e9e799ba24cef8a92be9273a877fc4f6472c361f53
|
7
|
+
data.tar.gz: bf86c5bbeac6c81f5f6c32552e17532c1761cb8dbeee256dcd532d1dbbe57472ad079f7bd324feb098217bfa9c7a26625107cd2dd7e9fe4c5f338834930050b4
|
data/lib/sy/composition.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
|
+
|
2
3
|
# Composition of quantities.
|
3
4
|
#
|
4
5
|
class SY::Composition < Hash
|
@@ -7,11 +8,13 @@ class SY::Composition < Hash
|
|
7
8
|
SR = SIMPLIFICATION_RULES = []
|
8
9
|
|
9
10
|
# SY::Amount and SY::Amount.relative are disposable:
|
11
|
+
#
|
10
12
|
SR << -> ꜧ {
|
11
13
|
ꜧ.reject! { |qnt, _| qnt == SY::Amount || qnt == SY::Amount.relative }
|
12
14
|
}
|
13
15
|
|
14
16
|
# Relative quantities of the composition are absolutized:
|
17
|
+
#
|
15
18
|
SR << -> ꜧ {
|
16
19
|
ꜧ.select { |qnt, _| qnt.relative? }.each { |qnt, exp|
|
17
20
|
ꜧ.delete qnt
|
@@ -20,12 +23,13 @@ class SY::Composition < Hash
|
|
20
23
|
}
|
21
24
|
|
22
25
|
# Any quantities with exponent zero can be deleted:
|
26
|
+
#
|
23
27
|
SR << -> ꜧ {
|
24
28
|
ꜧ.reject! { |_, exp| exp == 0 }
|
25
29
|
}
|
26
30
|
|
27
|
-
#
|
28
|
-
# LitreVolume into Molarity.
|
31
|
+
# FIXME: This quick fix simplification rule simplifies MoleAmount and
|
32
|
+
# LitreVolume into Molarity. This solution is insufficiently systematic.
|
29
33
|
#
|
30
34
|
SR << -> ꜧ {
|
31
35
|
begin
|
@@ -57,6 +61,25 @@ class SY::Composition < Hash
|
|
57
61
|
return ꜧ
|
58
62
|
}
|
59
63
|
|
64
|
+
# FIXME: This quick fix simplification rule simplifies LitreVolume times
|
65
|
+
# Molarity into MoleAmount. This solution is insufficiently systematic.
|
66
|
+
#
|
67
|
+
SR << -> ꜧ {
|
68
|
+
begin
|
69
|
+
q1, q2, q3 = SY::MoleAmount, SY::LitreVolume, SY::Molarity
|
70
|
+
rescue NameError; return ꜧ end
|
71
|
+
e2 = ꜧ.delete q2
|
72
|
+
e3 = ꜧ.delete q3
|
73
|
+
if e2 && e3 && e2 > 0 && e3 > 0 then
|
74
|
+
e2 -= 1
|
75
|
+
e3 -= 1
|
76
|
+
e1 = ꜧ.delete q1
|
77
|
+
ꜧ.update q1 => ( e1 ? e1 + 1 : 1 )
|
78
|
+
end
|
79
|
+
ꜧ.update q2 => e2 if e2 && e2 != 0
|
80
|
+
ꜧ.update q3 => e3 if e3 && e3 != 0
|
81
|
+
}
|
82
|
+
|
60
83
|
class << self
|
61
84
|
def singular quantity
|
62
85
|
self[ SY.Quantity( quantity ) => 1 ]
|
data/lib/sy/quantity.rb
CHANGED
@@ -87,6 +87,8 @@ class SY::Quantity
|
|
87
87
|
coerces( *Array( coerces ) )
|
88
88
|
Array( coerces_to ).each { |qnt| qnt.coerces self }
|
89
89
|
puts "Composition of the initialized instance is #{composition}." if SY::DEBUG
|
90
|
+
puts "Initialized instance is #{relative? ? :relative : :absolute}" if SY::DEBUG
|
91
|
+
puts "Initialized instance object_id is #{object_id}" if SY::DEBUG
|
90
92
|
end
|
91
93
|
|
92
94
|
# Simple quantity is one with simple composition. If nontrivial composition
|
@@ -264,6 +266,8 @@ class SY::Quantity
|
|
264
266
|
# Constructs a absolute magnitude of this quantity.
|
265
267
|
#
|
266
268
|
def magnitude amount
|
269
|
+
puts "self.object_id is #{object_id}" if SY::DEBUG
|
270
|
+
puts "composition is #{composition}" if SY::DEBUG
|
267
271
|
puts "Constructing #{self}#magnitude with amount #{amount}." if SY::DEBUG
|
268
272
|
Magnitude().new( of: self, amount: amount )
|
269
273
|
.tap { puts "#{self}#magnitude constructed!" if SY::DEBUG }
|
data/lib/sy/version.rb
CHANGED
data/lib/sy.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
#encoding: utf-8
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require 'y_support/null_object'
|
4
4
|
require 'y_support/name_magic'
|
@@ -69,7 +69,8 @@ module SY
|
|
69
69
|
# such as 42.unit to create magnitudes of SY::Amount.
|
70
70
|
puts "About to construct UNIT." if SY::DEBUG
|
71
71
|
UNIT = Unit.standard of: Amount
|
72
|
-
puts "UNIT constructed. SY::Unit instances are
|
72
|
+
puts "UNIT constructed. SY::Unit instances are " +
|
73
|
+
"#{SY::Unit.instance_names}" if SY::DEBUG
|
73
74
|
|
74
75
|
# AVOGADRO_CONSTANT (Nᴀ) is a certain well-known amount of things:
|
75
76
|
Nᴀ = AVOGADRO_CONSTANT = 6.02214e23
|
@@ -81,7 +82,8 @@ module SY
|
|
81
82
|
puts "About to construct MOLE." if SY::DEBUG
|
82
83
|
MOLE = Unit.standard of: MoleAmount, short: "mol", amount: Nᴀ.unit
|
83
84
|
puts SY::Unit.__instances__ if SY::DEBUG
|
84
|
-
puts "MOLE constructed. SY::Unit instances are
|
85
|
+
puts "MOLE constructed. SY::Unit instances are" +
|
86
|
+
"#{SY::Unit.instance_names}" if SY::DEBUG
|
85
87
|
|
86
88
|
# === Basic dimension L (length)
|
87
89
|
|
@@ -152,7 +154,7 @@ module SY
|
|
152
154
|
puts "CelsiusMagnitude#+ method with #{m2}" # FIXME: This message doesn't show.
|
153
155
|
return magnitude amount + m2.amount if
|
154
156
|
m2.quantity == SY::Temperature ||
|
155
|
-
|
157
|
+
m2.quantity.colleague == SY::Temperature
|
156
158
|
raise QuantityError, "Addition of Celsius temepratures is ambiguous!" if
|
157
159
|
m2.quantity == SY::CelsiusTemperature
|
158
160
|
super
|
@@ -162,7 +164,7 @@ module SY
|
|
162
164
|
puts "CelsiusMagnitude#- method with #{m2}" # FIXME: This message doesn't show.
|
163
165
|
return magnitude amount - m2.amount if
|
164
166
|
m2.quantity == SY::Temperature ||
|
165
|
-
|
167
|
+
m2.quantity.colleague == SY::Temperature
|
166
168
|
return super.( SY::Temperature ) if m2.quantity == SY::CelsiusTemperature
|
167
169
|
super
|
168
170
|
end
|
@@ -177,6 +179,7 @@ module SY
|
|
177
179
|
SY::CelsiusTemperature.absolute.magnitude self
|
178
180
|
end
|
179
181
|
end
|
182
|
+
|
180
183
|
# FIXME: Make this more systematic.
|
181
184
|
# FIXME: Make sure that SI prefixes may not be used with Celsius
|
182
185
|
# FIXME: Make sure that highly unusual SI prefixes may not be used
|
@@ -189,7 +192,6 @@ module SY
|
|
189
192
|
include SY::CelsiusMagnitude
|
190
193
|
end
|
191
194
|
|
192
|
-
|
193
195
|
# alias :°C :celsius # with U+00B0 DEGREE SIGN
|
194
196
|
# alias :˚C :celsius # with U+02DA RING ABOVE
|
195
197
|
# alias :℃ :celsius # U+2103 DEGREE CELSIUS
|
data/test/sy_test.rb
CHANGED
@@ -48,7 +48,7 @@ describe SY::Dimension do
|
|
48
48
|
assert_equal [0, 1], [:L, :M].map { |ß| SY.Dimension( :M ).send ß }
|
49
49
|
assert_equal [1, 0], [:L, :M].map { |ß| SY.Dimension( :L )[ß] }
|
50
50
|
|
51
|
-
# #to_a, #to_hash, #zero
|
51
|
+
# #to_a, #to_hash, #zero?
|
52
52
|
ll = SY::BASE_DIMENSIONS.letters
|
53
53
|
SY.Dimension( :M ).to_a.must_equal ll.map { |l| l == :M ? 1 : 0 }
|
54
54
|
SY.Dimension( :M ).to_hash.must_equal Hash[ ll.zip SY.Dimension( :M ).to_a ]
|
@@ -346,18 +346,15 @@ describe SY::Quantity, SY::Magnitude do
|
|
346
346
|
# joule
|
347
347
|
( 1.N * 1.m ).( SY::Energy ).must_equal 1.J
|
348
348
|
1e-23.J.K⁻¹.must_equal 1.0e-20.mJ.K⁻¹
|
349
|
-
|
350
|
-
|
351
349
|
|
352
350
|
# pascal
|
353
351
|
( 1.N / 1.m ** 2 ).( SY::Pressure ).must_be_within_epsilon 1.Pa, 1e-9
|
354
352
|
|
355
353
|
# watt
|
356
354
|
( 1.V * 1.A ).( SY::Power ).must_be_within_epsilon 1.W, 1e-9
|
357
|
-
|
358
355
|
|
359
356
|
# pretty representation
|
360
|
-
( 1.m / 3.s ).to_s.must_equal( "0.333.m.s⁻¹" )
|
357
|
+
( 1.m / 3.s ).to_s.must_equal( "0.333.m.s⁻¹" )
|
361
358
|
( 1.m / 7.01e7.s ).to_s.must_equal( "1.43e-08.m.s⁻¹" )
|
362
359
|
|
363
360
|
assert_equal 1.m, 1.s * 1.m.s⁻¹
|
@@ -372,6 +369,7 @@ describe SY::Quantity, SY::Magnitude do
|
|
372
369
|
assert_in_epsilon 1.µM, 1.µmol / 1.dm( 3 ).( SY::LitreVolume )
|
373
370
|
|
374
371
|
assert_equal SY::Molarity.relative, 1.mol.l⁻¹.quantity
|
372
|
+
assert_equal SY::MoleAmount.relative, 1.M.l.quantity
|
375
373
|
|
376
374
|
assert_equal 1 / SY::Time, 1 / SY::Time
|
377
375
|
assert_equal 1 / SY::Time.relative, 1 / SY::Time
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- boris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|