basic_temperature 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +33 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +12 -0
- data/.travis.yml +2 -1
- data/README.md +223 -9
- data/basic_temperature.gemspec +6 -1
- data/bin/console +4 -4
- data/docs/apple-touch-icon.png +0 -0
- data/docs/classes/BasicTemperature.html +1227 -0
- data/docs/classes/BasicTemperature/InitializationArgumentsError.html +94 -0
- data/docs/classes/BasicTemperature/InvalidDegreesError.html +94 -0
- data/docs/classes/BasicTemperature/InvalidNumericOrTemperatureError.html +94 -0
- data/docs/classes/BasicTemperature/InvalidScaleError.html +94 -0
- data/docs/classes/Object.html +274 -0
- data/docs/classes/Temperature.html +1227 -0
- data/docs/created.rid +4 -0
- data/docs/css/github.css +123 -0
- data/docs/css/main.css +374 -0
- data/docs/css/panel.css +361 -0
- data/docs/css/reset.css +48 -0
- data/docs/favicon.ico +0 -0
- data/docs/files/lib/basic_temperature/temperature_rb.html +73 -0
- data/docs/files/lib/basic_temperature/version_rb.html +84 -0
- data/docs/files/lib/basic_temperature_rb.html +112 -0
- data/docs/i/arrow-down.svg +8 -0
- data/docs/i/arrow-right.svg +8 -0
- data/docs/i/search.svg +12 -0
- data/docs/i/tree_bg.svg +8 -0
- data/docs/index.html +11 -0
- data/docs/js/highlight.pack.js +1 -0
- data/docs/js/jquery-1.3.2.min.js +19 -0
- data/docs/js/main.js +25 -0
- data/docs/js/navigation.js +105 -0
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search_index.js +1 -0
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searchdoc.js +465 -0
- data/docs/js/searcher.js +229 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/panel/index.html +47 -0
- data/docs/panel/links.html +12 -0
- data/docs/panel/tree.js +1 -0
- data/lib/basic_temperature.rb +552 -75
- data/lib/basic_temperature/temperature.rb +5 -0
- data/lib/basic_temperature/version.rb +1 -1
- data/logo.png +0 -0
- metadata +112 -4
- data/Gemfile.lock +0 -54
@@ -0,0 +1,94 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<title>BasicTemperature::InitializationArgumentsError</title>
|
5
|
+
<meta charset="UTF-8" />
|
6
|
+
<link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
|
7
|
+
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
|
8
|
+
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
|
9
|
+
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
10
|
+
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
|
13
|
+
|
14
|
+
<meta property="og:title" value="BasicTemperature::InitializationArgumentsError">
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
<meta name="description" content="Raised when Temperature.new is called with mixed positional and keyword arguments or without arguments at all.">
|
19
|
+
<meta property="og:description" content="Raised when Temperature.new is called with mixed positional and keyword arguments or without arguments at all.">
|
20
|
+
|
21
|
+
|
22
|
+
<meta name="keywords" content="BasicTemperature::InitializationArgumentsError class">
|
23
|
+
|
24
|
+
</head>
|
25
|
+
|
26
|
+
<body>
|
27
|
+
<div class="banner">
|
28
|
+
|
29
|
+
<h1>
|
30
|
+
<span class="type">Class</span>
|
31
|
+
BasicTemperature::InitializationArgumentsError
|
32
|
+
|
33
|
+
<span class="parent"><
|
34
|
+
|
35
|
+
StandardError
|
36
|
+
|
37
|
+
</span>
|
38
|
+
|
39
|
+
</h1>
|
40
|
+
<ul class="files">
|
41
|
+
|
42
|
+
<li><a href="../../files/lib/basic_temperature_rb.html">lib/basic_temperature.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
<div id="bodyContent">
|
47
|
+
<div id="content">
|
48
|
+
|
49
|
+
<div class="description">
|
50
|
+
|
51
|
+
<p>Raised when <code>Temperature.new</code> is called with mixed positional and keyword arguments or without arguments at all.</p>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<!-- Methods -->
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
</div>
|
91
|
+
|
92
|
+
</div>
|
93
|
+
</body>
|
94
|
+
</html>
|
@@ -0,0 +1,94 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<title>BasicTemperature::InvalidDegreesError</title>
|
5
|
+
<meta charset="UTF-8" />
|
6
|
+
<link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
|
7
|
+
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
|
8
|
+
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
|
9
|
+
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
10
|
+
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
|
13
|
+
|
14
|
+
<meta property="og:title" value="BasicTemperature::InvalidDegreesError">
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
<meta name="description" content="Raised when degrees is not a Numeric.">
|
19
|
+
<meta property="og:description" content="Raised when degrees is not a Numeric.">
|
20
|
+
|
21
|
+
|
22
|
+
<meta name="keywords" content="BasicTemperature::InvalidDegreesError class">
|
23
|
+
|
24
|
+
</head>
|
25
|
+
|
26
|
+
<body>
|
27
|
+
<div class="banner">
|
28
|
+
|
29
|
+
<h1>
|
30
|
+
<span class="type">Class</span>
|
31
|
+
BasicTemperature::InvalidDegreesError
|
32
|
+
|
33
|
+
<span class="parent"><
|
34
|
+
|
35
|
+
StandardError
|
36
|
+
|
37
|
+
</span>
|
38
|
+
|
39
|
+
</h1>
|
40
|
+
<ul class="files">
|
41
|
+
|
42
|
+
<li><a href="../../files/lib/basic_temperature_rb.html">lib/basic_temperature.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
<div id="bodyContent">
|
47
|
+
<div id="content">
|
48
|
+
|
49
|
+
<div class="description">
|
50
|
+
|
51
|
+
<p>Raised when <code>degrees</code> is not a Numeric.</p>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<!-- Methods -->
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
</div>
|
91
|
+
|
92
|
+
</div>
|
93
|
+
</body>
|
94
|
+
</html>
|
@@ -0,0 +1,94 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<title>BasicTemperature::InvalidNumericOrTemperatureError</title>
|
5
|
+
<meta charset="UTF-8" />
|
6
|
+
<link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
|
7
|
+
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
|
8
|
+
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
|
9
|
+
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
10
|
+
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
|
13
|
+
|
14
|
+
<meta property="og:title" value="BasicTemperature::InvalidNumericOrTemperatureError">
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
<meta name="description" content="Raised when other is not a Numeric or Temperature in math operations.">
|
19
|
+
<meta property="og:description" content="Raised when other is not a Numeric or Temperature in math operations.">
|
20
|
+
|
21
|
+
|
22
|
+
<meta name="keywords" content="BasicTemperature::InvalidNumericOrTemperatureError class">
|
23
|
+
|
24
|
+
</head>
|
25
|
+
|
26
|
+
<body>
|
27
|
+
<div class="banner">
|
28
|
+
|
29
|
+
<h1>
|
30
|
+
<span class="type">Class</span>
|
31
|
+
BasicTemperature::InvalidNumericOrTemperatureError
|
32
|
+
|
33
|
+
<span class="parent"><
|
34
|
+
|
35
|
+
StandardError
|
36
|
+
|
37
|
+
</span>
|
38
|
+
|
39
|
+
</h1>
|
40
|
+
<ul class="files">
|
41
|
+
|
42
|
+
<li><a href="../../files/lib/basic_temperature_rb.html">lib/basic_temperature.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
<div id="bodyContent">
|
47
|
+
<div id="content">
|
48
|
+
|
49
|
+
<div class="description">
|
50
|
+
|
51
|
+
<p>Raised when <code>other</code> is not a Numeric or <a href="../Temperature.html"><code>Temperature</code></a> in math operations.</p>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<!-- Methods -->
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
</div>
|
91
|
+
|
92
|
+
</div>
|
93
|
+
</body>
|
94
|
+
</html>
|
@@ -0,0 +1,94 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<title>BasicTemperature::InvalidScaleError</title>
|
5
|
+
<meta charset="UTF-8" />
|
6
|
+
<link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
|
7
|
+
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
|
8
|
+
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
|
9
|
+
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
10
|
+
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
|
13
|
+
|
14
|
+
<meta property="og:title" value="BasicTemperature::InvalidScaleError">
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
<meta name="description" content="Raised when scale can not be casted to any possible scale value. See SCALES.">
|
19
|
+
<meta property="og:description" content="Raised when scale can not be casted to any possible scale value. See SCALES.">
|
20
|
+
|
21
|
+
|
22
|
+
<meta name="keywords" content="BasicTemperature::InvalidScaleError class">
|
23
|
+
|
24
|
+
</head>
|
25
|
+
|
26
|
+
<body>
|
27
|
+
<div class="banner">
|
28
|
+
|
29
|
+
<h1>
|
30
|
+
<span class="type">Class</span>
|
31
|
+
BasicTemperature::InvalidScaleError
|
32
|
+
|
33
|
+
<span class="parent"><
|
34
|
+
|
35
|
+
StandardError
|
36
|
+
|
37
|
+
</span>
|
38
|
+
|
39
|
+
</h1>
|
40
|
+
<ul class="files">
|
41
|
+
|
42
|
+
<li><a href="../../files/lib/basic_temperature_rb.html">lib/basic_temperature.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
<div id="bodyContent">
|
47
|
+
<div id="content">
|
48
|
+
|
49
|
+
<div class="description">
|
50
|
+
|
51
|
+
<p>Raised when <code>scale</code> can not be casted to any possible scale value. See SCALES.</p>
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
<!-- Methods -->
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
</div>
|
91
|
+
|
92
|
+
</div>
|
93
|
+
</body>
|
94
|
+
</html>
|
@@ -0,0 +1,274 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html lang="en">
|
3
|
+
<head>
|
4
|
+
<title>Object</title>
|
5
|
+
<meta charset="UTF-8" />
|
6
|
+
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
|
7
|
+
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
|
8
|
+
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
|
9
|
+
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
|
10
|
+
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
|
11
|
+
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
|
12
|
+
|
13
|
+
|
14
|
+
<meta property="og:title" value="Object">
|
15
|
+
|
16
|
+
|
17
|
+
|
18
|
+
<meta name="keywords" content="Object class">
|
19
|
+
|
20
|
+
</head>
|
21
|
+
|
22
|
+
<body>
|
23
|
+
<div class="banner">
|
24
|
+
|
25
|
+
<h1>
|
26
|
+
<span class="type">Class</span>
|
27
|
+
Object
|
28
|
+
|
29
|
+
<span class="parent"><
|
30
|
+
|
31
|
+
BasicObject
|
32
|
+
|
33
|
+
</span>
|
34
|
+
|
35
|
+
</h1>
|
36
|
+
<ul class="files">
|
37
|
+
|
38
|
+
<li><a href="../files/lib/basic_temperature/temperature_rb.html">lib/basic_temperature/temperature.rb</a></li>
|
39
|
+
|
40
|
+
</ul>
|
41
|
+
</div>
|
42
|
+
<div id="bodyContent">
|
43
|
+
<div id="content">
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
|
70
|
+
<!-- Section constants -->
|
71
|
+
<div class="sectiontitle">Constants</div>
|
72
|
+
<table border='0' cellpadding='5'>
|
73
|
+
|
74
|
+
<tr valign='top'>
|
75
|
+
<td class="attr-name">Temperature</td>
|
76
|
+
<td>=</td>
|
77
|
+
<td class="attr-value">BasicTemperature</td>
|
78
|
+
</tr>
|
79
|
+
|
80
|
+
<tr valign='top'>
|
81
|
+
<td> </td>
|
82
|
+
<td colspan="2" class="attr-desc"><p><a href="Temperature.html"><code>Temperature</code></a> is a simple <a href="https://martinfowler.com/bliki/ValueObject.html">Value Object</a> for basic temperature operations like conversions from <code>Celsius</code> to <code>Fahrenhait</code> or <code>Kelvin</code> etc.</p>
|
83
|
+
|
84
|
+
<p>Supported scales: <code>Celsius</code>, <code>Fahrenheit</code>, <code>Kelvin</code> and <code>Rankine</code>.</p>
|
85
|
+
|
86
|
+
<h2 id="label-Creating+Temperatures">Creating Temperatures</h2>
|
87
|
+
|
88
|
+
<p>A new temperature can be created in multiple ways:</p>
|
89
|
+
<ul><li>
|
90
|
+
<p>Using keyword arguments:</p>
|
91
|
+
|
92
|
+
<pre><code>Temperature.new(degrees: 0, scale: :celsius)
|
93
|
+
</code></pre>
|
94
|
+
</li><li>
|
95
|
+
<p>Using positional arguments:</p>
|
96
|
+
|
97
|
+
<pre><code>Temperature.new(0, :celsius)
|
98
|
+
</code></pre>
|
99
|
+
</li><li>
|
100
|
+
<p>Even more concise way using <code>Temperature.[]</code> (an alias of <code>Temperature.new</code>):</p>
|
101
|
+
|
102
|
+
<pre><code>Temperature[0, :celsius]
|
103
|
+
</code></pre>
|
104
|
+
</li></ul>
|
105
|
+
|
106
|
+
<h2 id="label-Creating+Temperatures+from+already+existing+temperature+objects">Creating Temperatures from already existing temperature objects</h2>
|
107
|
+
|
108
|
+
<p>Sometimes it is useful to create a new temperature from already existing one.</p>
|
109
|
+
|
110
|
+
<p>For such cases, there are <a href="BasicTemperature.html#method-i-set_scale">set_degrees}[rdoc-ref:BasicTemperature#set_degrees and {set_scale</a>.</p>
|
111
|
+
|
112
|
+
<p>Since temperatures are <a href="https://martinfowler.com/bliki/ValueObject.html">Value Objects</a>, both methods returns new instances.</p>
|
113
|
+
|
114
|
+
<p>Examples:</p>
|
115
|
+
|
116
|
+
<pre><code>temperature = Temperature[0, :celsius]
|
117
|
+
# => 0 °C
|
118
|
+
|
119
|
+
new_temperature = temperature.set_degrees(15)
|
120
|
+
# => 15 °C
|
121
|
+
|
122
|
+
temperature = Temperature[0, :celsius]
|
123
|
+
# => 0 °C
|
124
|
+
|
125
|
+
new_temperature = temperature.set_scale(:kelvin)
|
126
|
+
# => 0 K
|
127
|
+
</code></pre>
|
128
|
+
|
129
|
+
<h2 id="label-Conversions">Conversions</h2>
|
130
|
+
|
131
|
+
<p>Temperatures can be converted to diffirent scales.</p>
|
132
|
+
|
133
|
+
<p>Currently, the following scales are supported: <code>Celsius</code>, <code>Fahrenheit</code>, <code>Kelvin</code> and <code>Rankine</code>.</p>
|
134
|
+
|
135
|
+
<pre><code>Temperature[20, :celsius].to_celsius
|
136
|
+
# => 20 °C
|
137
|
+
|
138
|
+
Temperature[20, :celsius].to_fahrenheit
|
139
|
+
# => 68 °F
|
140
|
+
|
141
|
+
Temperature[20, :celsius].to_kelvin
|
142
|
+
# => 293.15 K
|
143
|
+
|
144
|
+
Temperature[20, :celsius].to_rankine
|
145
|
+
# => 527.67 °R
|
146
|
+
</code></pre>
|
147
|
+
|
148
|
+
<p>If it is necessary to convert scale dynamically, <a href="BasicTemperature.html#method-i-to_scale">to_scale</a> method is available.</p>
|
149
|
+
|
150
|
+
<pre><code>Temperature[20, :celsius].to_scale(scale)
|
151
|
+
</code></pre>
|
152
|
+
|
153
|
+
<p>All conversion formulas are taken from <a href="https://www.rapidtables.com/convert/temperature/index.html">RapidTables</a>.</p>
|
154
|
+
|
155
|
+
<p>Conversion precision: 2 accurate digits after the decimal dot.</p>
|
156
|
+
|
157
|
+
<h2 id="label-Comparison">Comparison</h2>
|
158
|
+
|
159
|
+
<p><a href="Temperature.html"><code>Temperature</code></a> implements idiomatic <a href="https://ruby-doc.org/core/Comparable.html"><=> spaceship operator</a> and mixes in <a href="https://ruby-doc.org/core/Comparable.html">Comparable</a> module.</p>
|
160
|
+
|
161
|
+
<p>As a result, all methods from Comparable are available, e.g:</p>
|
162
|
+
|
163
|
+
<pre><code>Temperature[20, :celsius] < Temperature[25, :celsius]
|
164
|
+
# => true
|
165
|
+
|
166
|
+
Temperature[20, :celsius] <= Temperature[25, :celsius]
|
167
|
+
# => true
|
168
|
+
|
169
|
+
Temperature[20, :celsius] == Temperature[25, :celsius]
|
170
|
+
# => false
|
171
|
+
|
172
|
+
Temperature[20, :celsius] > Temperature[25, :celsius]
|
173
|
+
# => false
|
174
|
+
|
175
|
+
Temperature[20, :celsius] >= Temperature[25, :celsius]
|
176
|
+
# => false
|
177
|
+
|
178
|
+
Temperature[20, :celsius].between?(Temperature[15, :celsius], Temperature[25, :celsius])
|
179
|
+
# => true
|
180
|
+
|
181
|
+
# Starting from Ruby 2.4.6
|
182
|
+
Temperature[20, :celsius].clamp(Temperature[20, :celsius], Temperature[25, :celsius])
|
183
|
+
# => 20 °C
|
184
|
+
</code></pre>
|
185
|
+
|
186
|
+
<p>Please note, if <code>other</code> temperature has a different scale, temperature is automatically converted to that scale before comparison.</p>
|
187
|
+
|
188
|
+
<pre><code>Temperature[20, :celsius] == Temperature[293.15, :kelvin]
|
189
|
+
# => true
|
190
|
+
</code></pre>
|
191
|
+
|
192
|
+
<p>IMPORTANT !!!</p>
|
193
|
+
|
194
|
+
<p><code>degrees</code> are rounded to the nearest value with a precision of 2 decimal digits before comparison.</p>
|
195
|
+
|
196
|
+
<p>This means the following temperatures are considered as equal:</p>
|
197
|
+
|
198
|
+
<pre><code>Temperature[20.020, :celsius] == Temperature[20.024, :celsius]
|
199
|
+
# => true
|
200
|
+
|
201
|
+
Temperature[20.025, :celsius] == Temperature[20.029, :celsius]
|
202
|
+
# => true
|
203
|
+
</code></pre>
|
204
|
+
|
205
|
+
<p>while these ones are treated as NOT equal:</p>
|
206
|
+
|
207
|
+
<pre><code>Temperature[20.024, :celsius] == Temperature[20.029, :celsius]
|
208
|
+
# => false
|
209
|
+
</code></pre>
|
210
|
+
|
211
|
+
<h2 id="label-Math">Math</h2>
|
212
|
+
|
213
|
+
<h4 id="label-Addition-2FSubtraction.">Addition/Subtraction.</h4>
|
214
|
+
|
215
|
+
<pre><code>Temperature[20, :celsius] + Temperature[10, :celsius]
|
216
|
+
# => 30 °C
|
217
|
+
|
218
|
+
Temperature[20, :celsius] - Temperature[10, :celsius]
|
219
|
+
# => 10 °C
|
220
|
+
</code></pre>
|
221
|
+
|
222
|
+
<p>If second temperature has a different scale, first temperature is automatically converted to that scale before <code>degrees</code> addition/subtraction.</p>
|
223
|
+
|
224
|
+
<pre><code>Temperature[283.15, :kelvin] + Temperature[10, :celsius]
|
225
|
+
# => 10 °C
|
226
|
+
</code></pre>
|
227
|
+
|
228
|
+
<p>Returned temperature will have the same scale as the second temperature.</p>
|
229
|
+
|
230
|
+
<p>It is possible to add/subtract numerics.</p>
|
231
|
+
|
232
|
+
<pre><code>Temperature[20, :celsius] + 10
|
233
|
+
# => 30 °C
|
234
|
+
|
235
|
+
Temperature[20, :celsius] - 10
|
236
|
+
# => 10 °C
|
237
|
+
</code></pre>
|
238
|
+
|
239
|
+
<p>In such cases, returned temperature will have the same scale as the first temperature.</p>
|
240
|
+
|
241
|
+
<p>Also <a href="https://ruby-doc.org/core/Numeric.html#method-i-coerce">Ruby coersion mechanism</a> is supported.</p>
|
242
|
+
|
243
|
+
<pre><code>10 + Temperature[20, :celsius]
|
244
|
+
# => 30 °C
|
245
|
+
|
246
|
+
10 - Temperature[20, :celsius]
|
247
|
+
# => -10 °C
|
248
|
+
</code></pre>
|
249
|
+
|
250
|
+
<h4 id="label-Negation">Negation</h4>
|
251
|
+
|
252
|
+
<pre><code>-Temperature[20, :celsius]
|
253
|
+
# => -20 °C
|
254
|
+
</code></pre></td>
|
255
|
+
</tr>
|
256
|
+
|
257
|
+
|
258
|
+
</table>
|
259
|
+
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
<!-- Methods -->
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
</div>
|
271
|
+
|
272
|
+
</div>
|
273
|
+
</body>
|
274
|
+
</html>
|