sy 2.0.14 → 2.0.15
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 +4 -4
- data/lib/sy/magnitude.rb +2 -0
- data/lib/sy/quantity.rb +2 -1
- data/lib/sy/unit.rb +39 -48
- data/lib/sy/version.rb +1 -1
- data/test/sy_test.rb +4 -4
- 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: 03c905a6a5d6f664c79a57a4cabb98ef99366cff
|
4
|
+
data.tar.gz: 04c32a7833cbeeedb18e1d9ae24683b56386de9e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b99d28de71f57ac9243fbb6c03c1ca67a375f2708c0445fe05826105e7de98e0b10f03e27411f586b24af5d306f9c48522f9309e1251a4aa748b507ac370117
|
7
|
+
data.tar.gz: e50d6453484916e53cb368f7f897423046c239e741c9ba2da0615184f373b34fb2ba9dce6c6f2a62770fa3ba764c2902cc86a8975ab717c89ef5e35f89f6784e
|
data/lib/sy/magnitude.rb
CHANGED
data/lib/sy/quantity.rb
CHANGED
@@ -411,13 +411,14 @@ class SY::Quantity
|
|
411
411
|
mixin = relative? ? SY::SignedMagnitude : SY::AbsoluteMagnitude
|
412
412
|
qnt_ɴ_λ = -> { name ? "#{name}@%s" : "#<Quantity:#{object_id}@%s>" }
|
413
413
|
|
414
|
+
qnt = self
|
414
415
|
@Magnitude = Class.new do
|
415
416
|
include mmod
|
416
417
|
include mixin
|
417
418
|
|
418
419
|
singleton_class.class_exec do
|
419
420
|
define_method :zero do # Costructor of zero magnitudes
|
420
|
-
new amount: 0
|
421
|
+
new amount: 0, of: qnt
|
421
422
|
end
|
422
423
|
|
423
424
|
define_method :to_s do # Customized #to_s. It must be a proc,
|
data/lib/sy/unit.rb
CHANGED
@@ -7,7 +7,7 @@ module SY::Unit
|
|
7
7
|
PROTECTED_NAMES = [ "kilogram" ]
|
8
8
|
|
9
9
|
class << self
|
10
|
-
# Make Unit#instance ignore capitalization
|
10
|
+
# Make Unit#instance ignore capitalization, accept abbreviations.
|
11
11
|
#
|
12
12
|
def instance arg
|
13
13
|
begin
|
@@ -28,58 +28,49 @@ module SY::Unit
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def included target
|
31
|
-
target.
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
# puts im.include? down
|
57
|
-
warn w % [down, ɱ] if im.include? down
|
58
|
-
abbrev = new_instance.abbreviation
|
59
|
-
warn w % [abbrev, ɱ] if im.include? abbrev
|
60
|
-
end
|
31
|
+
target.namespace = self
|
32
|
+
|
33
|
+
name_set_closure do |name, new_instance, old_name|
|
34
|
+
ɴ = name.to_s
|
35
|
+
up, down = ɴ.upcase, ɴ.downcase
|
36
|
+
msg = "Unit must be either all-upper or all-lower case (#{ɴ} given)!"
|
37
|
+
fail NameError, msg unless ɴ == up || ɴ = down
|
38
|
+
# Reject the names starting with a full prefix.
|
39
|
+
pref = SY::PREFIX_TABLE.full_prefixes.find do |pref|
|
40
|
+
down.starts_with? pref unless pref.empty?
|
41
|
+
end
|
42
|
+
fail NameError, "Name #{ɴ} starts with #{pref}- prefix!" unless
|
43
|
+
SY::Unit::PROTECTED_NAMES.include? down if pref
|
44
|
+
# Warn about the method name conflicts in the #include target module
|
45
|
+
if new_instance.warns? then
|
46
|
+
w = SY::ExpressibleInUnits::COLLISION_WARNING
|
47
|
+
SY::ExpressibleInUnits.included_in.each do |modul|
|
48
|
+
im = modul.instance_methods
|
49
|
+
# puts ɱ, "class: #{ɱ.class}"
|
50
|
+
# puts im.size
|
51
|
+
# puts down
|
52
|
+
# puts im.include? down
|
53
|
+
warn w % [down, modul] if im.include? down
|
54
|
+
abbrev = new_instance.abbreviation
|
55
|
+
warn w % [abbrev, modul] if im.include? abbrev
|
61
56
|
end
|
62
|
-
up.to_sym
|
63
57
|
end
|
58
|
+
up.to_sym.tap { |sym| puts "name_set_closure #{sym}" if SY::DEBUG }
|
64
59
|
end
|
65
60
|
|
66
|
-
#
|
67
|
-
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
# the Unit class offers the opportunity for these prefix methods to cause
|
73
|
-
# <em>reframing</em> into a quantity specified by #quantity_by_prefix
|
74
|
-
# instance method. (This instance method normally returns the unit's own
|
75
|
-
# quantity unchanged, but can and should be overriden for those unit,
|
76
|
-
# which have area-specific prefix use.)
|
61
|
+
# We'll now define all the prefix methods on the target (#mili, #mega...),
|
62
|
+
# representing multiplication by the aprropriate factor (side effect being
|
63
|
+
# returning a non-unit magnitude). However, Unit offers the opportunity to
|
64
|
+
# _reframe_ into another quantity, specified by #quantity_by_prefix method.
|
65
|
+
# (This method normally returns the unit's own quantity, but can and should
|
66
|
+
# be overriden for prefixes indicating special domain (eg. +cm+)...
|
77
67
|
#
|
78
|
-
SY::PREFIX_TABLE.full_prefixes.each do |
|
79
|
-
unless
|
80
|
-
define_method
|
81
|
-
SY::Quantity
|
82
|
-
.
|
68
|
+
SY::PREFIX_TABLE.full_prefixes.each do |pref|
|
69
|
+
unless pref.empty?
|
70
|
+
define_method pref do
|
71
|
+
SY::Quantity
|
72
|
+
.instance( quantity_by_prefix( pref ) )
|
73
|
+
.magnitude( self * SY::PREFIX_TABLE.to_factor( pref ) )
|
83
74
|
end
|
84
75
|
end
|
85
76
|
end
|
data/lib/sy/version.rb
CHANGED
data/test/sy_test.rb
CHANGED
@@ -285,7 +285,7 @@ describe SY::Quantity, SY::Magnitude do
|
|
285
285
|
1.µM.quantity.absolute.name.must_equal :Molarity
|
286
286
|
7.µM.must_be_within_epsilon 5.µM + 2.µM, 1e-6
|
287
287
|
+1.s.must_equal 1.s
|
288
|
-
|
288
|
+
-1.s.must_equal -1 * 1.s # must raisen
|
289
289
|
assert_equal -(-(1.s)), +(1.s)
|
290
290
|
1.s⁻¹.quantity.must_equal ( 1.s ** -1 ).quantity
|
291
291
|
1.s⁻¹.quantity.must_equal ( 1 / 1.s ).quantity
|
@@ -304,9 +304,9 @@ describe SY::Quantity, SY::Magnitude do
|
|
304
304
|
( 1.s⁻¹ ).quantity.object_id.must_equal ( 1 / 1.s ).quantity.object_id
|
305
305
|
( 1 / 1.s ).must_equal 1.s⁻¹
|
306
306
|
1.s⁻¹.( SY::Frequency ).must_equal 1.Hz
|
307
|
-
|
308
|
-
|
309
|
-
|
307
|
+
7.°C.must_equal( 8.°C - 1.K )
|
308
|
+
(-15).°C.must_equal 258.15.K
|
309
|
+
7000.µM.must_be_within_epsilon( 7.mM, 1e-9 )
|
310
310
|
::SY::Unit.instances.map do |i|
|
311
311
|
begin
|
312
312
|
i.abbreviation
|
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.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- boris
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-06-
|
11
|
+
date: 2013-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|