sy 2.0.19 → 2.0.20
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/README.md +31 -31
- data/lib/sy/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8188db91a1be774b2ea6858b9b690c5533664748
|
4
|
+
data.tar.gz: aac76cadeb0e3737136ecb6e81887ac8e4388b57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a89e002696b4d93d231d7733c40d6aa9753dc20f1ff517e06d3c44abddc7cc335ce5a5de5d9a20c3ac53533fea73a86f640282529b7eda205b3a2db593abe45c
|
7
|
+
data.tar.gz: 769545fec641a14f785b81884e2c71fb60fe6e25655796eef2352b63d27ada1eca88f7856c1ccd549a83484359799ee16bf58bb1598f94ef755fbdea2565f76a
|
data/README.md
CHANGED
@@ -1,50 +1,50 @@
|
|
1
1
|
# SY - The physical units library.
|
2
2
|
|
3
|
-
The most prominent feature of SY is, that it extends the Numeric class
|
4
|
-
|
5
|
-
|
6
|
-
phys-units
|
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.
|
7
7
|
|
8
8
|
## Usage
|
9
9
|
|
10
|
-
Upon require 'sy'
|
11
|
-
computer will understand, that these numbers represent magnitudes of
|
12
|
-
physical quantity SY::Length expressed in the unit SY::METRE
|
13
|
-
we can use abbreviations (such as 5.m
|
14
|
-
5.kilometre
|
15
|
-
chaining (such as 5.m.s
|
16
|
-
read also the code file lib/sy.rb
|
17
|
-
|
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,
|
13
|
+
we can use abbreviations (such as `5.m`, `2.5.m`), prefixes (such as `5.km`,
|
14
|
+
`5.kilometre`, `5.km`), exponents (such as `5.m²` for 5 square metres), and
|
15
|
+
chaining (such as `5.m.s⁻¹` to denote speed of 5 metres per second). Please
|
16
|
+
read also the code file lib/sy.rb for the DSL statements defining default
|
17
|
+
quantities and their units.
|
18
18
|
|
19
19
|
## Unicode exponents
|
20
20
|
|
21
21
|
You should definitely learn how to type Unicode exponent characters, such
|
22
|
-
as
|
23
|
-
instead of 5.m.s
|
24
|
-
non-reused code. Unicode exponents make the physical models
|
25
|
-
be constructing with SY much more readable. And we know that
|
26
|
-
write once, read many times. So it pays off to type an
|
27
|
-
|
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
28
|
revisions.
|
29
29
|
|
30
30
|
## Method collisions
|
31
31
|
|
32
|
-
|
33
|
-
and abbreviations
|
34
|
-
|
35
|
-
minute, second etc.), which
|
36
|
-
|
37
|
-
|
38
|
-
will
|
39
|
-
|
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`).
|
40
41
|
|
41
42
|
## Contributing
|
42
43
|
|
43
|
-
SY has been written emphasizing the object model over plentitude of defined
|
44
|
-
units. There is plenty of room for defining units thus far not defined by SY
|
45
|
-
Also, the object model, though advanced, could possibly be refactored, eg.
|
46
|
-
|
47
|
-
introduced.
|
44
|
+
`SY` has been written emphasizing the object model over plentitude of defined
|
45
|
+
units. There is plenty of room for defining units thus far not defined by `SY`.
|
46
|
+
Also, the object model, though advanced, could possibly be refactored, eg. with
|
47
|
+
respect to the way that parametrized descendants of `Magnitude` are introduced.
|
48
48
|
|
49
49
|
1. Fork it
|
50
50
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
data/lib/sy/version.rb
CHANGED