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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e4e14ca002d2da647ce121e2f79b01fdced43697
4
- data.tar.gz: ac575e703f152e1b8f049ee30b8462a1f25a1baa
3
+ metadata.gz: 03c905a6a5d6f664c79a57a4cabb98ef99366cff
4
+ data.tar.gz: 04c32a7833cbeeedb18e1d9ae24683b56386de9e
5
5
  SHA512:
6
- metadata.gz: 96bc04ec2f55697c3906aa75e9aef8f6eeb968c08f963ad3b0935c1a72c137abea7b919b50cd57a48736d5d9e5d63a4b22c284350948469b9a796be51907ec43
7
- data.tar.gz: 6e74e90b0b4b1fddcc8e35f7c86939bda2a0759ecab362a994056a76e5a4ef35d0d376c8872c7ee0474e0be3166a78800d96e99c07f639be4fb6d9623a9196e5
6
+ metadata.gz: 5b99d28de71f57ac9243fbb6c03c1ca67a375f2708c0445fe05826105e7de98e0b10f03e27411f586b24af5d306f9c48522f9309e1251a4aa748b507ac370117
7
+ data.tar.gz: e50d6453484916e53cb368f7f897423046c239e741c9ba2da0615184f373b34fb2ba9dce6c6f2a62770fa3ba764c2902cc86a8975ab717c89ef5e35f89f6784e
data/lib/sy/magnitude.rb CHANGED
@@ -354,6 +354,8 @@ module SY::Magnitude
354
354
 
355
355
  # number, unit_presentation = choice
356
356
 
357
+ # return "#{amount} of #{quantity}"
358
+
357
359
  begin
358
360
 
359
361
  un = unit.short || unit.name
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 and accept abbreviations.
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.class_exec do
32
- # Let's set up the naming hook for NameMagic:
33
- name_set_closure do |name, new_instance, old_name|
34
- ɴ = name.to_s
35
- up, down = ɴ.upcase, ɴ.downcase
36
-
37
- # Check case (only all-upper or all-lower is acceptable).
38
- msg = "Unit must be either all-upper or all-lower case!"
39
- fail NameError, msg unless ɴ == up || ɴ = down
40
-
41
- # Reject the names starting with a full prefix.
42
- conflicter = SY::PREFIX_TABLE.full_prefixes
43
- .find { |prefix| down.starts_with? prefix unless prefix.empty? }
44
- fail NameError, "Name #{ɴ} starts with #{conflicter}- prefix!" unless
45
- SY::Unit::PROTECTED_NAMES.include? down if conflicter
46
-
47
- # Warn about method name conflicts in the target module(s), where
48
- # SY::ExpressibleInUnits mixin is included.
49
- if new_instance.warns? then
50
- w = ::SY::ExpressibleInUnits::COLLISION_WARNING
51
- ::SY::ExpressibleInUnits.included_in.each do |ɱ|
52
- im = ɱ.instance_methods
53
- # puts ɱ, "class: #{ɱ.class}"
54
- # puts im.size
55
- # puts down
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
- # name_get_closure { |name| name.to_s.downcase.to_sym }
67
-
68
- # Using eval, we'll now define all the prefix methods on the target, such
69
- # as #mili, #micro, #kilo, #mega, etc. These are defined only for units, to which
70
- # they represent multiplication by the factor of the prefix (side effect
71
- # of such multiplication is conversion to a normal magnitude). However,
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 |prefix|
79
- unless prefix.empty?
80
- define_method prefix do
81
- SY::Quantity.instance( quantity_by_prefix( prefix ) )
82
- .magnitude( self * SY::PREFIX_TABLE.to_factor( prefix ) )
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
@@ -1,5 +1,5 @@
1
1
  module SY
2
- VERSION = "2.0.14"
2
+ VERSION = "2.0.15"
3
3
  DEBUG = false # debug mode switch - sometimes there are lines like
4
4
  # puts "something" if SY::DEBUG
5
5
  end
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
- # -1.s.must_equal -1 * 1.s # must raise
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
- # 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 )
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.14
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-27 00:00:00.000000000 Z
11
+ date: 2013-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport