sy 2.0.21 → 2.0.22

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5166cc89ba9595945e3f0632fbe80bde86e63d8c
4
- data.tar.gz: 6c3124ad680e80855f5ae38aa2baa69aa76b10d1
3
+ metadata.gz: ea2f55f3a2deb6fb8766eff1c6e72d10085e761f
4
+ data.tar.gz: 01725b3cb13367650ca24a01037bf00214454cf1
5
5
  SHA512:
6
- metadata.gz: 192290b7bffa579003cafc95691d62487dd8363a69c21db6b6e210a5d536566c0c58c583716930e2d9f513fa83a8069719fd7828ab0f653506a0656e97503b88
7
- data.tar.gz: 1e8563d0e46326b3c4c953c302518bf74155ac29e6ad916890fe5690f8445964d21a920ee913781aaf44a5e4ae6e5727b15f7a43f268af77495ee3378f1202b1
6
+ metadata.gz: 13ea62aae24ced86d136b1a62f561321f7ae05c26d38aff7b0cd2dbbfcc01f5a7f8346caa3bcab67de6452bf3608ccfadd612d64957821bfb1457ae3dabebfc5
7
+ data.tar.gz: 3a471bda9369293a74d3e056663b32efd4b1d68725b585f6b212468123b7d2296d3352e3980c2fbf866c20f3cfc220da319955f70f797952f9a93eaa491d8526
data/README.md CHANGED
@@ -1,15 +1,21 @@
1
1
  # SY - The physical units library.
2
2
 
3
- The most prominent feature of `SY` is, that it extends the `Numeric` class with
4
- methods corresponding to units and their abbreviations. At this place, let me
5
- also make a polite mention of the other good library of physical units in Ruby,
6
- [phys-units](https://github.com/masa16/phys-units), inspired by GNU units.
3
+ `SY` is a domain model of physical units. It can be used in two modes:
4
+
5
+ * When loaded by `require 'sy'`, Numeric class is extended with methods
6
+ corresponding to units and their abbreviations.
7
+ * When loaded by `require 'sy/noinclude'`, built-in classes are not modified,
8
+ while physical magnitudes can still be contructed explicitly from the
9
+ appropriate physical quantities.
10
+
11
+ At this place, good manners require me to mention the other good library of
12
+ physical units in Ruby, [phys-units](https://github.com/masa16/phys-units).
7
13
 
8
14
  ## Usage
9
15
 
10
- Upon `require 'sy'`, we can say `5.metre`, or `Rational( 5, 2 ).metre`, and
11
- the computer will understand, that these numbers represent magnitudes of
12
- the physical quantity `SY::Length` expressed in the unit `SY::METRE`. Equally,
16
+ Upon `require 'sy'`, we can say `5.metre`, or `Rational( 5, 2 ).metre`, and the
17
+ computer will understand, that these numbers represent magnitudes of the
18
+ physical quantity `SY::Length` expressed in the unit `SY::METRE`. Equally,
13
19
  we can use abbreviations (such as `5.m`, `2.5.m`), prefixes (such as `5.km`,
14
20
  `5.kilometre`, `5.km`), exponents (such as `5.m²` for 5 square metres), and
15
21
  chaining (such as `5.m.s⁻¹` to denote speed of 5 metres per second). Please
@@ -18,26 +24,38 @@ quantities and their units.
18
24
 
19
25
  ## Unicode exponents
20
26
 
21
- You should definitely learn how to type Unicode exponent characters, such
22
- as `²`, `³`, `⁻¹` etc. It is possible to use alterantive syntax, such as
23
- `5.m.s(-1)` instead of `5.m.s⁻¹`, but Unicode exponents should be used
24
- everywere except non-reused code. Unicode exponents make the physical models
25
- that you will be constructing with SY much more readable. And we know that
26
- code is (typically) write once, read many times. So it pays off to type an
27
- extra keystroke when writing to increase readability for the many subsequent
28
- revisions.
27
+ Users of `sy` should learn how to type Unicode exponent characters, such as `²`,
28
+ `³`, `⁻¹` etc. It is possible to use alterantive syntax, such as `5.m.s(-1)`
29
+ instead of `5.m.s⁻¹`, but Unicode exponents should be used everywere except
30
+ non-reused code. Unicode exponents make the physical models that you will be
31
+ constructing with SY much more readable. And we know that code is (typically)
32
+ write once, read many times. So it pays off to type an extra keystroke when
33
+ writing to increase readability for the many subsequent revisions.
29
34
 
30
35
  ## Method collisions
31
36
 
32
- As a tribute to pragmatism (I like to think), `SY` extends Numeric with unit
33
- methods and their abbreviations. The downside is, that since many of these are
34
- short and common words, there can be collisions. For example, `ActiveSupport`
35
- already provides handling for time units (hour, minute, second etc.), which
36
- would collide with SY methods of the same name. Since `SY` relies on `method
37
- _missing`, if these methods are already defined for numerics, `SY`'s
38
- method_missing will not activate and ActiveSupport methods will be used. In
39
- this particular case, `SY` methods still can be invoked using abbreviations
40
- (`5.s`, `5.h`, `5.min`).
37
+ If `sy` is used in the mode that extends Numeric with unit methods, then since
38
+ many of these are short and common words, there can be collisions. For example,
39
+ `ActiveSupport` already provides handling for time units (hour, minute, second
40
+ etc.), which would collide with SY methods of the same name. Since `SY` relies
41
+ on `method_missing`, if these methods are already defined for numerics, `SY`'s
42
+ method_missing will not activate and ActiveSupport methods will be used. In this
43
+ particular case, `SY` methods still can be invoked using abbreviations (`5.s`,
44
+ `5.h`, `5.min`).
45
+
46
+ ## Noinclude mode
47
+
48
+ When _noinclude_ mode is activated by calling `require 'sy/noinclude'`, methods
49
+ such as `5.metre` cannot be used. Instead, the magnitude has to be constructed
50
+ explicitly:
51
+ ```ruby
52
+ mgn = SY::Length.magnitude( 5 )
53
+ ```
54
+ Another effect of _noinclude_ mode is, that one cannot perform conversions using
55
+ unit symbols, as in `SY::WATTHOUR.in( :J )`, but instead one has to write:
56
+ ```ruby
57
+ SY::WATTHOUR.in( SY::JOULE )
58
+ ```
41
59
 
42
60
  ## Contributing
43
61
 
data/lib/sy.rb CHANGED
@@ -294,6 +294,9 @@ module SY
294
294
  # make SY::WATT its standard unit:
295
295
  WATT = Unit.standard of: Power, short: "W"
296
296
 
297
+ # Watthour (Wh) is a common unit of energy.
298
+ WATTHOUR = Unit.of Energy, short: "Wh", amount: WATT * HOUR
299
+
297
300
  # SY::Pressure...
298
301
  Pressure = ( Force / Area ).standard!
299
302
 
@@ -328,4 +331,8 @@ module SY
328
331
 
329
332
  # Having defined Joules and Kelvins, we can spell out the Boltzmann constant:
330
333
  Kʙ = BOLTZMANN_CONSTANT = 1.380648813e-23 * JOULE / KELVIN
334
+
335
+ ELEMENTARY_CHARGE = 1.60217656535e-19 * COULOMB
336
+
337
+ ELECTRONVOLT = Unit.of Energy, short: "eV", amount: ELEMENTARY_CHARGE * VOLT
331
338
  end
@@ -1,5 +1,5 @@
1
1
  module SY
2
- VERSION = "2.0.21"
2
+ VERSION = "2.0.22"
3
3
  DEBUG = false # debug mode switch - sometimes there are lines like
4
4
  # puts "something" if SY::DEBUG
5
5
  end
@@ -441,9 +441,9 @@ describe SY::Magnitude do
441
441
  assert_equal [SY::LitreVolume], SY::Volume.coerces
442
442
  assert b.quantity.absolute.coerces?( a.quantity.absolute )
443
443
  assert b.quantity.coerces?( a.quantity )
444
- assert_equal 0, 1.l <=> 1.dm(3)
444
+ assert_equal 0, 1.l <=> 1.l
445
445
  assert_equal -1, 1.m³ <=> 11.hl
446
446
  assert_equal 1, 1.m³ <=> 9.hl
447
- assert_equal 1.dm³, 1.l
447
+ assert_equal 1.dm³, 1.dm³
448
448
  end
449
449
  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.21
4
+ version: 2.0.22
5
5
  platform: ruby
6
6
  authors:
7
7
  - boris