numru-units 1.7.0
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.
- data/ChangeLog +111 -0
- data/LICENSE.txt +34 -0
- data/Makefile +14 -0
- data/Rakefile +39 -0
- data/doc/Makefile +5 -0
- data/doc/units.html +241 -0
- data/doc/units.rd +232 -0
- data/install.rb +104 -0
- data/lib/numru/units.rb +3505 -0
- data/src/Makefile +35 -0
- data/src/dcunits.txt +212 -0
- data/src/lex.rb +434 -0
- data/src/makeutab.rb +87 -0
- data/src/mulnode.rb +150 -0
- data/src/namenode.rb +63 -0
- data/src/node.rb +210 -0
- data/src/numbernode.rb +53 -0
- data/src/pownode.rb +98 -0
- data/src/rules.rb +65 -0
- data/src/shiftnode.rb +63 -0
- data/src/test.rb +122 -0
- data/src/timenode.rb +136 -0
- data/src/units.racc +2728 -0
- data/src/units.rb +3505 -0
- data/src/units.rd +139 -0
- data/src/utab.rb +1456 -0
- metadata +96 -0
data/ChangeLog
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
Thu Aug 4 2011 T Horinouchi
|
2
|
+
* version 1.7 released ((cvs) tag: numru-units-1_7)
|
3
|
+
* LICENSE.txt: added (BSD 2-clause)
|
4
|
+
* doc/units.rd, doc/units.html: updated (added entry to dcunits.txt)
|
5
|
+
Wed Aug 3 2011 T Horinouchi
|
6
|
+
* mulnode.rb: to_s changed to explicitly handle a Float
|
7
|
+
whose value is an integer.
|
8
|
+
* Makefile: adopet to the change in the "tail" command
|
9
|
+
(tail +2 --> tail -n +2).
|
10
|
+
Mon Mar 15 2010 T Horinouchi
|
11
|
+
* version 1.6 released ((cvs) tag: numru-units-1_6)
|
12
|
+
Fri May 23 2008 T Horinouchi
|
13
|
+
* dcunits.txt: added the following units: percent [S], % [S],
|
14
|
+
permil [S], centigrade [P], millibar [P]
|
15
|
+
* rules.rb: changed not to accept empty unit_spec
|
16
|
+
* lex.rb:
|
17
|
+
* method do_parse2: to treat empty string units '' as '1'
|
18
|
+
(to return NumberNode.new(1) instead of ErrorNode.new(''))
|
19
|
+
Fri Feb 8 2008 T Koshiro
|
20
|
+
* lex.rb: next_token: at least one space or tab character is required
|
21
|
+
before/after 'per', 'after', 'from', 'since', 'ref'
|
22
|
+
Wed Aug 24 2005 T Horinouchi
|
23
|
+
* version 1.5 released ((cvs) tag: numru-units-1_5)
|
24
|
+
Wed Jun 8 2005 T Horinouchi
|
25
|
+
* lex.rb:
|
26
|
+
* debug in RE_SECOND
|
27
|
+
* debug in time zone parser (many bugs)
|
28
|
+
* improvement in time parser RE_TIME to support hhmm type
|
29
|
+
in addition to [h]h:[m]m
|
30
|
+
* timenode.rb:
|
31
|
+
* TimeNode#utcsod : debug in time zone treatment
|
32
|
+
(IT WAS A FATAL BUG!!)
|
33
|
+
* TimeNode#to_s : debug in the expression of seconds (not to
|
34
|
+
take the floor of seconds).
|
35
|
+
Wed May 25 2005 T Horinouchi
|
36
|
+
* version 1.4 released ((cvs) tag: numru-units-1_4)
|
37
|
+
* lex.rb: debug in RE_HOUR. It did not handle hours after 20 properly.
|
38
|
+
Mon Nov 29 2004 T Horinouchi
|
39
|
+
* timenode.rb: class XDate: added to_date (for intenal usage), and
|
40
|
+
modified +(ohter) and -(ohter) methods to use it as long as possible.
|
41
|
+
This is to widen the coverage of time -- up to now, only very
|
42
|
+
recent years (such as AD19xx-20xx) are accpeted, since the
|
43
|
+
Time intrincic class is always used.
|
44
|
+
Tue Nov 9 2004 T Horinouchi
|
45
|
+
* lex.rb: Units#convert2: changed warning messaging to show backtrace
|
46
|
+
Sun Aug 10 2004 T Horinouchi
|
47
|
+
* lex.rb: lex.rb Units#convert, Units#==: debug not to change
|
48
|
+
(reduce5) self and input units.
|
49
|
+
Sun Aug 8 2004 T Horinouchi
|
50
|
+
* version 1.3 released
|
51
|
+
* mulnode.rb: improved Multi#sort: to eliminate Number[1] if
|
52
|
+
length >= 2. Then, Units.new('1m').reduce5.to_s gives 'm';
|
53
|
+
it used to give '1 m'.
|
54
|
+
* numbernode.rb: defined == (to compare by values -- implicitly
|
55
|
+
used in the new Multi#sort)
|
56
|
+
* dcunits.txt: added some units from udunits: Pascal, deg[KF],
|
57
|
+
deg_[CFK], degree[CFK], [Cc]elcius, angular_(degree|minute|secont),
|
58
|
+
[Ff]ahrenheit, farad, gravity, conventional_mercury, mercury,
|
59
|
+
Hg, hg, Julian_year, common_year, tesla
|
60
|
+
* lex.rb: debug === (aliased to ==. The change on May 4 was enbug).
|
61
|
+
debug =~: to handle other classes (return false)
|
62
|
+
Tue May 4 2004 T Horinouchi
|
63
|
+
* pownode.rb: PowNode#to_s: if the expopnent is 1, omit it.
|
64
|
+
* lex.rb: debug === (to allow a difference of a factor and/or offset)
|
65
|
+
Sun May 2 2004 T Horinouchi
|
66
|
+
* dcunits.txt: added degree_east/degrees_east etc.
|
67
|
+
Sun Mar 21 2004 T Horinouchi
|
68
|
+
* version 1.2 released ((cvs) tag: numru-units-1_2)
|
69
|
+
Fri Mar 19 2004 T Horinouchi
|
70
|
+
* mulnode.rb: MutiNode#value: to return 1 if @children.size == 0
|
71
|
+
* dcunits.txt: added degC
|
72
|
+
* lex.rb: convert2: warn if $VERBOSE --> warn regardress $VERBOSE
|
73
|
+
Mon Mar 1 2004 T Horinouchi
|
74
|
+
* version 1.1 released ((cvs) tag: numru-units-1_1)
|
75
|
+
Mon Mar 1 2004 E Toyoda
|
76
|
+
* test.rb: revised due to the change of reduce4; updated
|
77
|
+
* timenode.rb debugged (Unexpected generation of Float by Date#-
|
78
|
+
is avoided using Date-like wrapper to Time.)
|
79
|
+
* node.rb: unalias (such as "kilometer" -> "10^3 m") will not
|
80
|
+
occur at reduce4. (plurals still recognized in reduce4)
|
81
|
+
* namenode.rb,numbernode.rb: unused methods "nameable?" removed
|
82
|
+
* makeutab.rb: Bugfix: units like "second" or "metre" were not
|
83
|
+
unaliased to its primary name (such as "s" or "m") due to
|
84
|
+
improper parsing of dcunits.txt.
|
85
|
+
Sun Feb 29 2004 E Toyoda (Commited by T Horinouchi)
|
86
|
+
* makeutab.rb: debug plural treatment (/y$/ -> /[^aeou]y$/)
|
87
|
+
Fri Feb 27 2004 T Horinouchi
|
88
|
+
* src/lex.rb: added Units#convert2 (similar to Units#convert but
|
89
|
+
more suitable for UNumeric constraction).
|
90
|
+
debug in =~
|
91
|
+
* test.rb: added a test of =~
|
92
|
+
Thu Feb 26 2004 T Horinouchi
|
93
|
+
* src/lex.rb: added Units#factor_and_offset
|
94
|
+
* doc/units.rd: updated
|
95
|
+
Wed Feb 25 2004 T Horinouchi
|
96
|
+
* src/Makefile: add -l option to racc -- not to convert line #s
|
97
|
+
for better readability of exception messages
|
98
|
+
* Makefile: (very minor) cp --> cp -p
|
99
|
+
Tue Feb 24 2004 T Horinouchi
|
100
|
+
* version 1.0 released
|
101
|
+
* packaging for distribution
|
102
|
+
* put Units into the NumRu module ( --> class NumRu::Units )
|
103
|
+
* cvs version control started (CVSROOT=
|
104
|
+
dennou-k.gfd-dennou.org:/GFD_Dennou_Club/ftp/arch/ruby/cvsroot
|
105
|
+
project name: numru-units)
|
106
|
+
Fri Feb 6 2004 TOYODA Eizi (log written by T Horinouchi 2004/03/24)
|
107
|
+
* revised
|
108
|
+
Fri Nov 7 2003 TOYODA Eizi (log written by T Horinouchi 2004/03/24)
|
109
|
+
* revized
|
110
|
+
Fri Oct 24 2003(or before) TOYODA Eizi(log written by T Horinouchi 2004/03/24)
|
111
|
+
* created
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
NumRu::Units is copyrighted free software by Takeshi Horinouchi and
|
2
|
+
GFD Dennou Club (http://www.gfd-dennou.org/).
|
3
|
+
|
4
|
+
Copyright 2011 (C) Takeshi Horinouchi and GFD Dennou Club
|
5
|
+
(http://www.gfd-dennou.org/) All rights reserved.
|
6
|
+
|
7
|
+
Redistribution and use in source and binary forms, with or without
|
8
|
+
modification, are permitted provided that the following conditions are
|
9
|
+
met:
|
10
|
+
|
11
|
+
1. Redistributions of source code must retain the above copyright
|
12
|
+
notice, this list of conditions and the following disclaimer.
|
13
|
+
|
14
|
+
2. Redistributions in binary form must reproduce the above copyright
|
15
|
+
notice, this list of conditions and the following disclaimer in
|
16
|
+
the documentation and/or other materials provided with the
|
17
|
+
distribution.
|
18
|
+
|
19
|
+
THIS SOFTWARE IS PROVIDED BY GFD DENNOU CLUB AND CONTRIBUTORS ``AS IS''
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
21
|
+
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
22
|
+
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GFD DENNOU CLUB OR
|
23
|
+
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
24
|
+
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
25
|
+
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
26
|
+
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
27
|
+
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
28
|
+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
29
|
+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
30
|
+
|
31
|
+
The views and conclusions contained in the software and documentation
|
32
|
+
are those of the authors and should not be interpreted as representing
|
33
|
+
official policies, either expressed or implied, of Takeshi Horinouchi
|
34
|
+
and GFD Dennou Club.
|
data/Makefile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'rake/gempackagetask'
|
2
|
+
|
3
|
+
NAME = 'numru-units'
|
4
|
+
VER = '1.7.0'
|
5
|
+
|
6
|
+
PKG_FILES = FileList[
|
7
|
+
'**',
|
8
|
+
'lib/**/*',
|
9
|
+
'doc/**/*',
|
10
|
+
'src/**/*'
|
11
|
+
]
|
12
|
+
|
13
|
+
spec = Gem::Specification.new do |s|
|
14
|
+
s.name = NAME
|
15
|
+
s.version = VER
|
16
|
+
s.authors = ["Eizi Toyoda","Takeshi Horinouchi"]
|
17
|
+
s.email = ['eriko@gfd-dennou.org']
|
18
|
+
s.homepage = 'http://www.gfd-dennou.org/arch/ruby/products/numru-units/'
|
19
|
+
s.licenses = ["Takeshi Horinouchi", "GFD Dennou Club"]
|
20
|
+
s.platform = Gem::Platform::RUBY
|
21
|
+
s.summary = %q{Class to handle units of physical quantities}
|
22
|
+
s.description = %q{This is a class to handle units of physical quantities. It covers most functionality of UNIDATA's UDUNITS Library, however, with a more sophisticated handling of string expressions. See the documentation for more infomation.}
|
23
|
+
|
24
|
+
s.files = PKG_FILES.to_a
|
25
|
+
s.require_paths = ['lib']
|
26
|
+
#s.test_files = Dir.glob("test/*")
|
27
|
+
#s.has_rdoc = true
|
28
|
+
s.required_ruby_version = Gem::Requirement.new(">= 1.6")
|
29
|
+
#s.add_runtime_dependency(%q<narray>, [">= 0"])
|
30
|
+
#s.add_runtime_dependency(%q<narray_miss>, [">= 0"])
|
31
|
+
#s.extra_rdoc_files = ['README']
|
32
|
+
|
33
|
+
#s.extensions << "install.rb"
|
34
|
+
end
|
35
|
+
|
36
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
37
|
+
pkg.gem_spec = spec
|
38
|
+
pkg.need_tar = true
|
39
|
+
end
|
data/doc/Makefile
ADDED
data/doc/units.html
ADDED
@@ -0,0 +1,241 @@
|
|
1
|
+
<?xml version="1.0" ?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
<html xmlns="http://www.w3.org/1999/xhtml">
|
6
|
+
<head>
|
7
|
+
<title>units.rd</title>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
<h1><a name="label-0" id="label-0">class NumRu::Units</a></h1><!-- RDLabel: "class NumRu::Units" -->
|
11
|
+
<ul>
|
12
|
+
<li><a href="#label-1">Overview</a></li>
|
13
|
+
<li><a href="#label-2">Installation</a></li>
|
14
|
+
<li><a href="#label-3">Usage Examples</a></li>
|
15
|
+
<li><a href="#label-4">Class Methods</a></li>
|
16
|
+
<li><a href="#label-8">Instance Methods</a></li>
|
17
|
+
<li><a href="http://ruby.gfd-dennou.org/products/numru-units/doc/dcunits.txt">Supported units</a> (Plural form allowed if the second field is "P")</li>
|
18
|
+
</ul>
|
19
|
+
<h2><a name="label-1" id="label-1">Overview</a></h2><!-- RDLabel: "Overview" -->
|
20
|
+
<p>A class of units of physical quantities.</p>
|
21
|
+
<p>This class covers most functionality of UNIDATA's
|
22
|
+
<a href="http://www.unidata.ucar.edu/packages/udunits/">UDUNITS Library</a>,
|
23
|
+
however, with a more sophisticated handling of string expressions. </p>
|
24
|
+
<p>UDUNITS always decomposes units into the four base units and discards
|
25
|
+
the original string expressions. Therefore, 'hPa' always becomes
|
26
|
+
'100 kg.m-1.sec-1', and 'day' always becomes '86400 sec'. On the other
|
27
|
+
hand, this library tries to keep the original expressions as much as
|
28
|
+
possible by default, while allowing partial to complete decompositions
|
29
|
+
if needed.</p>
|
30
|
+
<h2><a name="label-2" id="label-2">Installation</a></h2><!-- RDLabel: "Installation" -->
|
31
|
+
<p>Move to the top directly of this library (where you find
|
32
|
+
the file install.rb). Then, type in the following:</p>
|
33
|
+
<pre>% ruby install.rb</pre>
|
34
|
+
<h2><a name="label-3" id="label-3">Usage Examples</a></h2><!-- RDLabel: "Usage Examples" -->
|
35
|
+
<p>Here is an example using the "irb" interactive shell ("%" is the
|
36
|
+
command prompt, and ">>" is the irb prompt -- Type in those after it
|
37
|
+
to test. "=>" shows the result.):</p>
|
38
|
+
<pre>% irb --simple-prompt
|
39
|
+
>> require "numru/units"
|
40
|
+
=> true
|
41
|
+
>> un1 = NumRu::Units.new('kg.m2/s')
|
42
|
+
=> Units{kg.m2/s}
|
43
|
+
>> un2 = NumRu::Units.new('g.m')
|
44
|
+
=> Units{g.m}
|
45
|
+
>> un3 = un1 / un2
|
46
|
+
=> Units[Multi[Pow[Name[g], Number[-1]], Name[kg], Pow[Name[m], Number[1]], Pow[Name[s], Number[-1]]]]
|
47
|
+
>> un1.to_s
|
48
|
+
=> "kg.m2/s"
|
49
|
+
>> un2.to_s
|
50
|
+
=> "g.m"
|
51
|
+
>> un3.to_s
|
52
|
+
=> "g-1 kg.m1 s-1"
|
53
|
+
>> un3.reduce5
|
54
|
+
=> Units[Multi[Number[1000], Pow[Name[m], Number[1]], Pow[Name[s], Number[-1]]]]
|
55
|
+
>> un3.to_s
|
56
|
+
=> "1000 m1 s-1"</pre>
|
57
|
+
<p>Note the difference between the results of un3.to_s
|
58
|
+
before and after un3.reduce5,
|
59
|
+
where the former retains the literal expression
|
60
|
+
of each atomic unit, while the latter does the maximum reduction.
|
61
|
+
You can change the default behavior by using the class method
|
62
|
+
reduce_level=:</p>
|
63
|
+
<pre>>> NumRu::Units.reduce_level = 5
|
64
|
+
=> :reduce5
|
65
|
+
>> un3.to_s
|
66
|
+
=> "1000 m1 s-1"</pre>
|
67
|
+
<p>Note that you can eliminate the prefix NumRu:: by "including"
|
68
|
+
it:</p>
|
69
|
+
<pre>>> require "numru/units"
|
70
|
+
=> true
|
71
|
+
>> include NumRu
|
72
|
+
=> Object
|
73
|
+
>> un1 = Units.new('kg.m2/s')
|
74
|
+
=> Units{kg.m2/s}
|
75
|
+
>> Units.reduce_level = 5
|
76
|
+
=> :reduce5</pre>
|
77
|
+
<h2><a name="label-4" id="label-4">Class Methods</a></h2><!-- RDLabel: "Class Methods" -->
|
78
|
+
<p>In what follows, the prefix NumRu:: is omitted for conciseness.
|
79
|
+
See <a href="#label-3">Usage Examples</a> on this issue.</p>
|
80
|
+
<dl>
|
81
|
+
<dt><h4><a name="label-5" id="label-5"><code>Units.new(<var>string</var>)</code></a></h4></dt><!-- RDLabel: "Units.new" -->
|
82
|
+
<dd>
|
83
|
+
<p>Constructor.</p>
|
84
|
+
<p>ARGUMENTS</p>
|
85
|
+
<ul>
|
86
|
+
<li>string (String): string expression of the units.
|
87
|
+
[factor] units; [factor] time units [since ...] (see EXAMPLES below)</li>
|
88
|
+
</ul>
|
89
|
+
<p>RETURN VALUE</p>
|
90
|
+
<ul>
|
91
|
+
<li>a Units</li>
|
92
|
+
</ul>
|
93
|
+
<p>EXAMPLE</p>
|
94
|
+
<pre>units = Units.new('kg.m2/s')
|
95
|
+
units = Units.new('100 m')
|
96
|
+
units = Units.new('g/kg')
|
97
|
+
units = Units.new('hour since 2003-10-01 00:00:0 +0:00')
|
98
|
+
units = Units.new('hour since 2003-10-01') # same as above
|
99
|
+
units = Units.new('minutes since 2003-10-01 03:15:22.5 -6:00')</pre></dd>
|
100
|
+
<dt><h4><a name="label-6" id="label-6"><code>Units[string]</code></a></h4></dt><!-- RDLabel: "Units[string]" -->
|
101
|
+
<dd>
|
102
|
+
Same as <a href="#label-5">Units.new</a></dd>
|
103
|
+
<dt><h4><a name="label-7" id="label-7"><code>Units.reduce_level=(<var>n</var>)</code></a></h4></dt><!-- RDLabel: "Units.reduce_level=" -->
|
104
|
+
<dd>
|
105
|
+
<p>Set the reduction level before <a href="#label-9">to_s</a> is applied.</p>
|
106
|
+
<p>ARGUMENTS</p>
|
107
|
+
<ul>
|
108
|
+
<li>n (Integer): the reduction level. The default value is 4.
|
109
|
+
Use 5 if you want a full reduction. Levels lower than 4
|
110
|
+
will not be needed.</li>
|
111
|
+
</ul></dd>
|
112
|
+
</dl>
|
113
|
+
<h2><a name="label-8" id="label-8">Instance Methods</a></h2><!-- RDLabel: "Instance Methods" -->
|
114
|
+
<dl>
|
115
|
+
<dt><h4><a name="label-9" id="label-9"><code>to_s</code></a></h4></dt><!-- RDLabel: "to_s" -->
|
116
|
+
<dd>
|
117
|
+
Returns a string expression of the units.</dd>
|
118
|
+
<dt><h4><a name="label-10" id="label-10"><code>*(<var>other</var>)</code></a></h4></dt><!-- RDLabel: "*" -->
|
119
|
+
<dd>
|
120
|
+
<p>Multiplies self with another units.
|
121
|
+
Applies <a href="#label-16">reduce4</a> to format the string expression of the result.</p>
|
122
|
+
<p>ARGUMENTS</p>
|
123
|
+
<ul>
|
124
|
+
<li>other [Units]: the other units</li>
|
125
|
+
</ul>
|
126
|
+
<p>RETURN VALUE</p>
|
127
|
+
<ul>
|
128
|
+
<li>a Units</li>
|
129
|
+
</ul></dd>
|
130
|
+
<dt><h4><a name="label-11" id="label-11"><code>/(<var>other</var>)</code></a></h4></dt><!-- RDLabel: "/" -->
|
131
|
+
<dd>
|
132
|
+
<p>Divides self with another units.
|
133
|
+
Applies <a href="#label-16">reduce4</a> to format the string expression of the result.</p>
|
134
|
+
<p>ARGUMENTS</p>
|
135
|
+
<ul>
|
136
|
+
<li>other [Units]: the other units</li>
|
137
|
+
</ul>
|
138
|
+
<p>RETURN VALUE</p>
|
139
|
+
<ul>
|
140
|
+
<li>a Units</li>
|
141
|
+
</ul></dd>
|
142
|
+
<dt><h4><a name="label-12" id="label-12"><code>**(<var>pow</var>)</code></a></h4></dt><!-- RDLabel: "**" -->
|
143
|
+
<dd>
|
144
|
+
<p>Power.
|
145
|
+
Applies <a href="#label-16">reduce4</a> to format the string expression of the result.</p>
|
146
|
+
<p>ARGUMENTS</p>
|
147
|
+
<ul>
|
148
|
+
<li>pow [Numeric -- Integer, Rational, or Float]</li>
|
149
|
+
</ul>
|
150
|
+
<p>RETURN VALUE</p>
|
151
|
+
<ul>
|
152
|
+
<li>a Units</li>
|
153
|
+
</ul></dd>
|
154
|
+
<dt><h4><a name="label-13" id="label-13"><code>==(<var>other</var>)</code></a></h4></dt><!-- RDLabel: "==" -->
|
155
|
+
<dd>
|
156
|
+
Whether the two units are the same.
|
157
|
+
('m/s' and 'm.s-1' are the same, for instance.)</dd>
|
158
|
+
<dt><h4><a name="label-14" id="label-14"><code>===(<var>other</var>)</code></a></h4></dt><!-- RDLabel: "===" -->
|
159
|
+
<dd>
|
160
|
+
Same as <a href="#label-13">==</a>.</dd>
|
161
|
+
<dt><h4><a name="label-15" id="label-15"><code>=~(<var>other</var>)</code></a></h4></dt><!-- RDLabel: "=~" -->
|
162
|
+
<dd>
|
163
|
+
Whether the two units are compatible (i.e., with the same dimensionality).
|
164
|
+
('m/s' and '10 m.s-1' are compatible, for instance.)</dd>
|
165
|
+
<dt><h4><a name="label-16" id="label-16"><code>reduce4</code></a></h4></dt><!-- RDLabel: "reduce4" -->
|
166
|
+
<dd>
|
167
|
+
<p>Moderately reduces the string expression of the units (destructive method).
|
168
|
+
This method preserves string expression of atomic units.
|
169
|
+
See also <a href="#label-17">reduce5</a>.</p>
|
170
|
+
<p>RETURN VALUE</p>
|
171
|
+
<ul>
|
172
|
+
<li>self</li>
|
173
|
+
</ul>
|
174
|
+
<p>EXAMPLE</p>
|
175
|
+
<pre>Untis.new('hour/hour').reduce4.to_s
|
176
|
+
# => "1"
|
177
|
+
Units.new('mm/m').reduce4.to_s
|
178
|
+
# => "mm.m-1"</pre></dd>
|
179
|
+
<dt><h4><a name="label-17" id="label-17"><code>reduce5</code></a></h4></dt><!-- RDLabel: "reduce5" -->
|
180
|
+
<dd>
|
181
|
+
<p>Aggressively reduces the string expression of the units (destructive method).
|
182
|
+
See also <a href="#label-16">reduce4</a>.</p>
|
183
|
+
<p>RETURN VALUE</p>
|
184
|
+
<ul>
|
185
|
+
<li>self</li>
|
186
|
+
</ul>
|
187
|
+
<p>EXAMPLE</p>
|
188
|
+
<pre>Units.new('hour/hour').reduce4.to_s
|
189
|
+
# => "1"
|
190
|
+
Units.new('mm/m').reduce5.to_s
|
191
|
+
# => "0.001"</pre></dd>
|
192
|
+
<dt><h4><a name="label-18" id="label-18"><code>convert(<var>numeric</var>, <var>to_units</var>)</code></a></h4></dt><!-- RDLabel: "convert" -->
|
193
|
+
<dd>
|
194
|
+
<p>Converts a numeric of the current units (=self) to <var>to_units</var>.</p>
|
195
|
+
<p>ARGUMENTS</p>
|
196
|
+
<ul>
|
197
|
+
<li>numeric [Numeric]: the numeric to convert</li>
|
198
|
+
<li>to_units [Units]: the units converted into</li>
|
199
|
+
</ul>
|
200
|
+
<p>RETURN VALUE</p>
|
201
|
+
<ul>
|
202
|
+
<li>a Numeric</li>
|
203
|
+
</ul>
|
204
|
+
<p>EXCEPTIONS</p>
|
205
|
+
<ul>
|
206
|
+
<li><var>self</var> and <var>to_units</var> are incompatible.</li>
|
207
|
+
</ul></dd>
|
208
|
+
<dt><h4><a name="label-19" id="label-19"><code>convert2(<var>val</var>, <var>to_units</var>)</code></a></h4></dt><!-- RDLabel: "convert2" -->
|
209
|
+
<dd>
|
210
|
+
<p>Like <a href="#label-18">convert</a>, but (1) accpets any Numeric-like objects, and (2)
|
211
|
+
does not raise an exception even if the two units are incompatible --
|
212
|
+
in this case, simply returns <var>val</var> (warned).</p>
|
213
|
+
<p>ARGUMENTS</p>
|
214
|
+
<ul>
|
215
|
+
<li>val [a Numeric-like class, for which * and + are defined]:
|
216
|
+
the value to convert</li>
|
217
|
+
<li>to_units [Units]: the units converted into</li>
|
218
|
+
</ul>
|
219
|
+
<p>RETURN VALUE</p>
|
220
|
+
<ul>
|
221
|
+
<li>an object with the same class as <var>val</var>.</li>
|
222
|
+
</ul></dd>
|
223
|
+
<dt><h4><a name="label-20" id="label-20"><code>factor_and_offset(<var>to_units</var>)</code></a></h4></dt><!-- RDLabel: "factor_and_offset" -->
|
224
|
+
<dd>
|
225
|
+
<p>Returns the factor and offset to convert from <var>self</var> to <var>to_units</var>.
|
226
|
+
The conversion is done as scale_factor * operand + add_offset.</p>
|
227
|
+
<p>ARGUMENTS</p>
|
228
|
+
<ul>
|
229
|
+
<li>to_units [Units]: the units to be converted into</li>
|
230
|
+
</ul>
|
231
|
+
<p>RETURN VALUE</p>
|
232
|
+
<ul>
|
233
|
+
<li>[ scale_factor, add_offset ] (a 2-element Array, where both are Numeric)</li>
|
234
|
+
</ul>
|
235
|
+
<p>EXAMPLE</p>
|
236
|
+
<pre>scale_factor, add_offset = from_units.factor_and_offset(to_units)
|
237
|
+
to = scale_factor * from + add_offset</pre></dd>
|
238
|
+
</dl>
|
239
|
+
|
240
|
+
</body>
|
241
|
+
</html>
|