sy 2.0.20 → 2.0.21

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: 8188db91a1be774b2ea6858b9b690c5533664748
4
- data.tar.gz: aac76cadeb0e3737136ecb6e81887ac8e4388b57
3
+ metadata.gz: 5166cc89ba9595945e3f0632fbe80bde86e63d8c
4
+ data.tar.gz: 6c3124ad680e80855f5ae38aa2baa69aa76b10d1
5
5
  SHA512:
6
- metadata.gz: a89e002696b4d93d231d7733c40d6aa9753dc20f1ff517e06d3c44abddc7cc335ce5a5de5d9a20c3ac53533fea73a86f640282529b7eda205b3a2db593abe45c
7
- data.tar.gz: 769545fec641a14f785b81884e2c71fb60fe6e25655796eef2352b63d27ada1eca88f7856c1ccd549a83484359799ee16bf58bb1598f94ef755fbdea2565f76a
6
+ metadata.gz: 192290b7bffa579003cafc95691d62487dd8363a69c21db6b6e210a5d536566c0c58c583716930e2d9f513fa83a8069719fd7828ab0f653506a0656e97503b88
7
+ data.tar.gz: 1e8563d0e46326b3c4c953c302518bf74155ac29e6ad916890fe5690f8445964d21a920ee913781aaf44a5e4ae6e5727b15f7a43f268af77495ee3378f1202b1
data/lib/sy.rb CHANGED
@@ -51,7 +51,11 @@ require_relative 'sy/matrix'
51
51
  # be used. In this particular case, SY methods still can be invoked using
52
52
  # abbreviations (5.s, 5.h, 5.min)
53
53
  #
54
- Numeric.class_exec { include ::SY::ExpressibleInUnits }
54
+ module SY
55
+ AUTOINCLUDE = true unless defined? ::SY::AUTOINCLUDE
56
+ end
57
+
58
+ Numeric.class_exec { include ::SY::ExpressibleInUnits } if SY::AUTOINCLUDE
55
59
 
56
60
  # === Instead of introduction
57
61
  #
@@ -80,7 +84,7 @@ module SY
80
84
 
81
85
  # And let SY::MOLE be its standard unit, related to SY::Amount via Nᴀ:
82
86
  puts "About to construct MOLE." if SY::DEBUG
83
- MOLE = Unit.standard of: MoleAmount, short: "mol", amount: Nᴀ.unit
87
+ MOLE = Unit.standard of: MoleAmount, short: "mol", amount: Nᴀ * UNIT
84
88
  puts SY::Unit.__instances__ if SY::DEBUG
85
89
  puts "MOLE constructed. SY::Unit instances are" +
86
90
  "#{SY::Unit.instance_names}" if SY::DEBUG
@@ -101,11 +105,13 @@ module SY
101
105
  # Let SY::KILOGRAM be its standard unit:
102
106
  KILOGRAM = Unit.standard of: Mass, short: "kg"
103
107
  # Let SY::GRAM be another unit of SY::Mass, equal to 0.001.kg:
104
- GRAM = Unit.of Mass, amount: 0.001.kg, short: "g"
108
+ GRAM = Unit.of Mass, amount: 0.001 * KILOGRAM, short: "g"
105
109
  # Let SY::TON be another...
106
- TON = Unit.of Mass, amount: 1000.kg, short: "t"
110
+ TON = Unit.of Mass, amount: 1000 * KILOGRAM, short: "t"
107
111
  # And SY::DALTON another...
108
- DALTON = Unit.of Mass, short: "Da", amount: 1.66053892173e-27.kg
112
+ DALTON = Unit.of Mass,
113
+ short: "Da",
114
+ amount: 1.66053892173e-27 * KILOGRAM
109
115
 
110
116
  # === Basic dimension T
111
117
 
@@ -115,9 +121,9 @@ module SY
115
121
  # Let SY::SECOND be its standard unit:
116
122
  SECOND = Unit.standard of: Time, short: "s"
117
123
  # Let SY::MINUTE be another unit:
118
- MINUTE = Unit.of Time, short: "min", amount: 60.s
124
+ MINUTE = Unit.of Time, short: "min", amount: 60 * SECOND
119
125
  # And SY::HOUR another:
120
- HOUR = Unit.of Time, short: "h", amount: 60.min
126
+ HOUR = Unit.of Time, short: "h", amount: 60 * MINUTE
121
127
 
122
128
  # === Basic dimension Q
123
129
 
@@ -136,14 +142,14 @@ module SY
136
142
  KELVIN = Unit.standard of: Temperature, short: "K"
137
143
 
138
144
  # Now let us define a useful constant:
139
- TP_H₂O = TRIPLE_POINT_OF_WATER = 273.15.K
145
+ TP_H₂O = TRIPLE_POINT_OF_WATER = 273.15 * KELVIN
140
146
 
141
147
  # Celsius temperature is a little bit peculiar in that it has offset of
142
148
  # 273.15.K with respect to Kelvin temperature, and I am not sure whether
143
149
  # at this moment SY is handling this right. But nevertheless:
144
150
  CelsiusTemperature = Quantity.of :Θ, coerces_to: Temperature
145
151
 
146
- CELSIUS_MEASURE = SY::Measure.simple_offset( TRIPLE_POINT_OF_WATER.in( :K ) )
152
+ CELSIUS_MEASURE = SY::Measure.simple_offset( TRIPLE_POINT_OF_WATER.to_f )
147
153
 
148
154
  # Degree celsius is SY::CELSIUS
149
155
  CELSIUS = Unit.standard( of: CelsiusTemperature,
@@ -206,8 +212,8 @@ module SY
206
212
 
207
213
  # HUMAN_BODY_TEMPERATURE = 37.°C.( KELVIN )
208
214
  # STANDARD_TEMPERATURE = 25.°C.( KELVIN )
209
- HUMAN_BODY_TEMPERATURE = TP_H₂O + 37.K
210
- STANDARD_LABORATORY_TEMPERATURE = TP_H₂O + 25.K
215
+ HUMAN_BODY_TEMPERATURE = TP_H₂O + 37 * KELVIN
216
+ STANDARD_LABORATORY_TEMPERATURE = TP_H₂O + 25 * KELVIN
211
217
 
212
218
  # === Dimensionless quantities
213
219
 
@@ -230,7 +236,7 @@ module SY
230
236
  LitreVolume = Quantity.of Volume.dimension, coerces_to: Volume
231
237
 
232
238
  # SY::LITRE is the standard unit of SY::LitreVolume:
233
- LITRE = Unit.standard of: LitreVolume, short: "l", amount: 1.dm³
239
+ LITRE = Unit.standard of: LitreVolume, short: "l", amount: 0.001 * METRE ** 3
234
240
 
235
241
  # At this point, there are certain things to note. Since standard units of
236
242
  # SY::Area and SY::Volume have not been specified, they are assumed to be
@@ -280,7 +286,7 @@ module SY
280
286
  # make SY::JOULE its standard unit:
281
287
  JOULE = Unit.standard of: Energy, short: "J"
282
288
  # SY::CALORIE means thermochemical calorie:
283
- CALORIE = Unit.of Energy, short: "cal", amount: 4.184.J
289
+ CALORIE = Unit.of Energy, short: "cal", amount: 4.184 * JOULE
284
290
 
285
291
  # SY::Power...
286
292
  Power = ( Energy / Time ).standard!
@@ -321,5 +327,5 @@ module SY
321
327
  Molecularity = Amount / LitreVolume
322
328
 
323
329
  # Having defined Joules and Kelvins, we can spell out the Boltzmann constant:
324
- Kʙ = BOLTZMANN_CONSTANT = 1.380648813e-23.J.K⁻¹
330
+ Kʙ = BOLTZMANN_CONSTANT = 1.380648813e-23 * JOULE / KELVIN
325
331
  end
data/lib/sy/imperial.rb CHANGED
@@ -1,31 +1,33 @@
1
- # -*- coding: utf-8 -*-
2
- require 'sy'
1
+ # encoding: utf-8
2
+
3
+ require_relative '../sy'
3
4
 
4
5
  # Imperial units.
5
6
  #
6
7
  module SY
7
8
  # === Length
8
- INCH = Unit.of Length, amount: 25.4.mm # short: 'in' would be ambiguous
9
- FOOT = Unit.of Length, short: 'ft', amount: 12.inch
10
- YARD = Unit.of Length, short: 'yd', amount: 3.ft
9
+ INCH = Unit.of Length, amount: 25.4 * 0.001 * METRE
10
+ # short: 'in' would be ambiguous
11
+ FOOT = Unit.of Length, short: 'ft', amount: 12 * INCH
12
+ YARD = Unit.of Length, short: 'yd', amount: 3 * FOOT
11
13
  # forget CHAIN and FURLONG
12
- MILE = Unit.of Length, short: 'mi', amount: 5_280.ft
13
- FATHOM = Unit.of Length, short: 'ftm', amount: 1.853184.m
14
- NAUTICAL_MILE = Unit.of Length, amount: 1000.fathom
14
+ MILE = Unit.of Length, short: 'mi', amount: 5_280 * FOOT
15
+ FATHOM = Unit.of Length, short: 'ftm', amount: 1.853184 * METRE
16
+ NAUTICAL_MILE = Unit.of Length, amount: 1000 * FATHOM
15
17
 
16
18
  # === Area
17
- ACRE = Unit.of Area, amount: ( 1.0 / 640 ).mile²
19
+ ACRE = Unit.of Area, amount: ( 1.0 / 640 ) * MILE ** 2
18
20
 
19
21
  # === Volume
20
- PINT = Unit.of Volume, amount: 568.26125.cm³
22
+ PINT = Unit.of Volume, amount: 568.26125 * ( 0.01 * METRE ) ** 3
21
23
  # FIXME: PINT = Unit.of Volume, amount: 568.26125.ml didn't work, it gave 1000 times more value
22
24
  # something is wrong with the conversion mechanics
23
- QUART = Unit.of Volume, amount: 2.pint
24
- GALLON = Unit.of Volume, short: 'gal', amount: 8.pint
25
+ QUART = Unit.of Volume, amount: 2 * PINT
26
+ GALLON = Unit.of Volume, short: 'gal', amount: 8 * PINT
25
27
 
26
28
  # === Mass
27
- POUND = Unit.of Mass, short: 'lb', amount: 453.59237.g
28
- OUNCE = Unit.of Mass, short: 'oz', amount: ( 1.0 / 16 ).lb
29
- STONE = Unit.of Mass, amount: 14.lb
30
- IMPERIAL_TON = Unit.of Mass, amount: 2240.lb
29
+ POUND = Unit.of Mass, short: 'lb', amount: 453.59237 * GRAM
30
+ OUNCE = Unit.of Mass, short: 'oz', amount: ( 1.0 / 16 ) * POUND
31
+ STONE = Unit.of Mass, amount: 14 * POUND
32
+ IMPERIAL_TON = Unit.of Mass, amount: 2240 * POUND
31
33
  end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+
3
+ # Setting +AUTOINCLUDE+ constant to _false_ at the beginning of the +sy+ loading
4
+ # process prevents automatic inclusion of +SY::ExpressibleInUnits+ in +Numeric+.
5
+ #
6
+ module SY
7
+ AUTOINCLUDE = false
8
+ end
9
+
10
+ require_relative '../sy'
data/lib/sy/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module SY
2
- VERSION = "2.0.20"
2
+ VERSION = "2.0.21"
3
3
  DEBUG = false # debug mode switch - sometimes there are lines like
4
4
  # puts "something" if SY::DEBUG
5
5
  end
@@ -0,0 +1,44 @@
1
+ #! /usr/bin/ruby
2
+ # encoding: utf-8
3
+
4
+ # **************************************************************************
5
+ # THIS IS SPEC-STYLE TEST FILE FOR SY PHYSICAL UNITS LIBRARY
6
+ # **************************************************************************
7
+
8
+ # The following will load Ruby spec-style library
9
+ require 'mathn'
10
+ require 'minitest/autorun'
11
+
12
+
13
+ # **************************************************************************
14
+ # THE SPECIFICATIONS START HERE
15
+ # **************************************************************************
16
+
17
+ describe "case of require 'sy/noinclude'" do
18
+ before do
19
+ # The following will load SY library
20
+ # require 'sy'
21
+ require './../lib/sy/noinclude'
22
+ end
23
+
24
+ it "should show at least some signs of life" do
25
+ SY::Length.magnitude( 1 ).must_equal SY::METRE
26
+ SY::Length.magnitude( 2 ).must_equal SY::METRE * 2
27
+ SY::Volume.magnitude( 1 ).must_equal SY::METRE ** 3
28
+ # without caring for exhaustive test coverage...
29
+ end
30
+ end
31
+
32
+ describe "require 'sy/noinclude'; require 'sy/imperial'" do
33
+ before do
34
+ # The following will load SY library
35
+ # require 'sy'
36
+ require './../lib/sy/noinclude'
37
+ require './../lib/sy/imperial'
38
+ end
39
+
40
+ it "should show signs of life" do
41
+ SY::YARD.must_equal SY::FOOT * 3
42
+ SY::POUND.must_equal 16 * SY::OUNCE
43
+ end
44
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sy
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.20
4
+ version: 2.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris
@@ -47,12 +47,14 @@ files:
47
47
  - lib/sy/mapping.rb
48
48
  - lib/sy/matrix.rb
49
49
  - lib/sy/measure.rb
50
+ - lib/sy/noinclude.rb
50
51
  - lib/sy/quantity.rb
51
52
  - lib/sy/signed_magnitude.rb
52
53
  - lib/sy/unit.rb
53
54
  - lib/sy/version.rb
54
55
  - lib/sy/wildcard_zero.rb
55
56
  - sy.gemspec
57
+ - test/noinclude_test.rb
56
58
  - test/sy_test.rb
57
59
  homepage: ''
58
60
  licenses: []
@@ -78,4 +80,5 @@ signing_key:
78
80
  specification_version: 4
79
81
  summary: Simple and concise way to express physical units.
80
82
  test_files:
83
+ - test/noinclude_test.rb
81
84
  - test/sy_test.rb