basic_temperature 0.2.2 → 1.0.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.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.inch.yml +3 -0
  3. data/.rubocop.yml +3 -0
  4. data/CHANGELOG.md +68 -7
  5. data/README.md +41 -61
  6. data/bin/console +1 -1
  7. data/docs/classes/BasicTemperature.html +27 -1129
  8. data/docs/classes/BasicTemperature/Temperature.html +1239 -0
  9. data/docs/classes/BasicTemperature/Temperature/AdditionalHelpers.html +78 -0
  10. data/docs/classes/BasicTemperature/Temperature/Assertions.html +78 -0
  11. data/docs/classes/BasicTemperature/Temperature/Casting.html +78 -0
  12. data/docs/classes/BasicTemperature/Temperature/Errors.html +109 -0
  13. data/docs/classes/BasicTemperature/Temperature/Errors/InitializationArguments.html +94 -0
  14. data/docs/classes/BasicTemperature/Temperature/Errors/InvalidDegrees.html +94 -0
  15. data/docs/classes/BasicTemperature/Temperature/Errors/InvalidNumeric.html +94 -0
  16. data/docs/classes/BasicTemperature/Temperature/Errors/InvalidNumericOrTemperature.html +94 -0
  17. data/docs/classes/BasicTemperature/Temperature/Errors/InvalidScale.html +94 -0
  18. data/docs/classes/BasicTemperature/Temperature/Initialization.html +78 -0
  19. data/docs/classes/BasicTemperature/Temperature/Memoization.html +78 -0
  20. data/docs/classes/BasicTemperature/Temperature/Rounding.html +78 -0
  21. data/docs/classes/Object.html +3 -175
  22. data/docs/created.rid +12 -4
  23. data/docs/files/lib/basic_temperature/alias_rb.html +73 -0
  24. data/docs/files/lib/basic_temperature/temperature/additional_helpers_rb.html +94 -0
  25. data/docs/files/lib/basic_temperature/temperature/assertions_rb.html +94 -0
  26. data/docs/files/lib/basic_temperature/temperature/casting_rb.html +94 -0
  27. data/docs/files/lib/basic_temperature/temperature/errors_rb.html +119 -0
  28. data/docs/files/lib/basic_temperature/temperature/initialization_rb.html +94 -0
  29. data/docs/files/lib/basic_temperature/temperature/memoization_rb.html +94 -0
  30. data/docs/files/lib/basic_temperature/temperature/rounding_rb.html +94 -0
  31. data/docs/files/lib/basic_temperature/temperature_rb.html +17 -1
  32. data/docs/files/lib/basic_temperature/version_rb.html +2 -2
  33. data/docs/files/lib/basic_temperature_rb.html +2 -30
  34. data/docs/js/navigation.js.gz +0 -0
  35. data/docs/js/search_index.js +1 -1
  36. data/docs/js/search_index.js.gz +0 -0
  37. data/docs/js/searcher.js.gz +0 -0
  38. data/docs/panel/links.html +16 -0
  39. data/docs/panel/tree.js +1 -1
  40. data/lib/basic_temperature.rb +3 -700
  41. data/lib/basic_temperature/alias.rb +5 -0
  42. data/lib/basic_temperature/temperature.rb +515 -2
  43. data/lib/basic_temperature/temperature/additional_helpers.rb +17 -0
  44. data/lib/basic_temperature/temperature/assertions.rb +30 -0
  45. data/lib/basic_temperature/temperature/casting.rb +19 -0
  46. data/lib/basic_temperature/temperature/errors.rb +50 -0
  47. data/lib/basic_temperature/temperature/initialization.rb +32 -0
  48. data/lib/basic_temperature/temperature/memoization.rb +26 -0
  49. data/lib/basic_temperature/temperature/rounding.rb +13 -0
  50. data/lib/basic_temperature/version.rb +2 -2
  51. metadata +32 -2
@@ -35,7 +35,7 @@
35
35
  </h1>
36
36
  <ul class="files">
37
37
 
38
- <li><a href="../files/lib/basic_temperature/temperature_rb.html">lib/basic_temperature/temperature.rb</a></li>
38
+ <li><a href="../files/lib/basic_temperature/alias_rb.html">lib/basic_temperature/alias.rb</a></li>
39
39
 
40
40
  </ul>
41
41
  </div>
@@ -74,184 +74,12 @@
74
74
  <tr valign='top'>
75
75
  <td class="attr-name">Temperature</td>
76
76
  <td>=</td>
77
- <td class="attr-value">BasicTemperature</td>
77
+ <td class="attr-value">BasicTemperature::Temperature</td>
78
78
  </tr>
79
79
 
80
80
  <tr valign='top'>
81
81
  <td>&nbsp;</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
- # =&gt; 0 °C
118
-
119
- new_temperature = temperature.set_degrees(15)
120
- # =&gt; 15 °C
121
-
122
- temperature = Temperature[0, :celsius]
123
- # =&gt; 0 °C
124
-
125
- new_temperature = temperature.set_scale(:kelvin)
126
- # =&gt; 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
- # =&gt; 20 °C
137
-
138
- Temperature[20, :celsius].to_fahrenheit
139
- # =&gt; 68 °F
140
-
141
- Temperature[20, :celsius].to_kelvin
142
- # =&gt; 293.15 K
143
-
144
- Temperature[20, :celsius].to_rankine
145
- # =&gt; 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] &lt; Temperature[25, :celsius]
164
- # =&gt; true
165
-
166
- Temperature[20, :celsius] &lt;= Temperature[25, :celsius]
167
- # =&gt; true
168
-
169
- Temperature[20, :celsius] == Temperature[25, :celsius]
170
- # =&gt; false
171
-
172
- Temperature[20, :celsius] &gt; Temperature[25, :celsius]
173
- # =&gt; false
174
-
175
- Temperature[20, :celsius] &gt;= Temperature[25, :celsius]
176
- # =&gt; false
177
-
178
- Temperature[20, :celsius].between?(Temperature[15, :celsius], Temperature[25, :celsius])
179
- # =&gt; true
180
-
181
- # Starting from Ruby 2.4.6
182
- Temperature[20, :celsius].clamp(Temperature[20, :celsius], Temperature[25, :celsius])
183
- # =&gt; 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
- # =&gt; 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
- # =&gt; true
200
-
201
- Temperature[20.025, :celsius] == Temperature[20.029, :celsius]
202
- # =&gt; 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
- # =&gt; 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
- # =&gt; 30 °C
217
-
218
- Temperature[20, :celsius] - Temperature[10, :celsius]
219
- # =&gt; 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
- # =&gt; 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
- # =&gt; 30 °C
234
-
235
- Temperature[20, :celsius] - 10
236
- # =&gt; 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
- # =&gt; 30 °C
245
-
246
- 10 - Temperature[20, :celsius]
247
- # =&gt; -10 °C
248
- </code></pre>
249
-
250
- <h4 id="label-Negation">Negation</h4>
251
-
252
- <pre><code>-Temperature[20, :celsius]
253
- # =&gt; -20 °C
254
- </code></pre></td>
82
+ <td colspan="2" class="attr-desc"></td>
255
83
  </tr>
256
84
 
257
85
 
data/docs/created.rid CHANGED
@@ -1,4 +1,12 @@
1
- Thu, 26 Mar 2020 12:49:37 -0000
2
- lib/basic_temperature.rb Thu, 26 Mar 2020 14:43:32 +0200
3
- lib/basic_temperature/temperature.rb Thu, 19 Mar 2020 21:16:10 +0200
4
- lib/basic_temperature/version.rb Mon, 23 Mar 2020 21:38:55 +0200
1
+ Thu, 16 Apr 2020 14:45:35 -0000
2
+ lib/basic_temperature.rb Thu, 26 Mar 2020 17:27:15 +0200
3
+ lib/basic_temperature/temperature.rb Thu, 16 Apr 2020 17:45:21 +0300
4
+ lib/basic_temperature/version.rb Thu, 26 Mar 2020 17:27:15 +0200
5
+ lib/basic_temperature/alias.rb Thu, 26 Mar 2020 17:27:15 +0200
6
+ lib/basic_temperature/temperature/errors.rb Thu, 16 Apr 2020 17:45:21 +0300
7
+ lib/basic_temperature/temperature/initialization.rb Thu, 26 Mar 2020 17:27:15 +0200
8
+ lib/basic_temperature/temperature/casting.rb Thu, 26 Mar 2020 17:27:15 +0200
9
+ lib/basic_temperature/temperature/additional_helpers.rb Thu, 26 Mar 2020 17:27:15 +0200
10
+ lib/basic_temperature/temperature/rounding.rb Thu, 26 Mar 2020 17:27:15 +0200
11
+ lib/basic_temperature/temperature/memoization.rb Thu, 26 Mar 2020 17:27:15 +0200
12
+ lib/basic_temperature/temperature/assertions.rb Thu, 16 Apr 2020 17:45:21 +0300
@@ -0,0 +1,73 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>alias.rb</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
+ </head>
14
+
15
+ <body>
16
+ <div class="banner">
17
+
18
+ <h1>
19
+ alias.rb
20
+ </h1>
21
+ <ul class="files">
22
+
23
+ <li>
24
+ lib/basic_temperature/alias.rb
25
+
26
+ </li>
27
+ <li>Last modified: 2020-03-26 17:27:15 +0200</li>
28
+ </ul>
29
+ </div>
30
+
31
+ <div id="bodyContent">
32
+ <div id="content">
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+
61
+
62
+
63
+
64
+ <!-- Methods -->
65
+
66
+
67
+
68
+
69
+ </div>
70
+
71
+ </div>
72
+ </body>
73
+ </html>
@@ -0,0 +1,94 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>additional_helpers.rb</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
+ </head>
14
+
15
+ <body>
16
+ <div class="banner">
17
+
18
+ <h1>
19
+ additional_helpers.rb
20
+ </h1>
21
+ <ul class="files">
22
+
23
+ <li>
24
+ lib/basic_temperature/temperature/additional_helpers.rb
25
+
26
+ </li>
27
+ <li>Last modified: 2020-03-26 17:27:15 +0200</li>
28
+ </ul>
29
+ </div>
30
+
31
+ <div id="bodyContent">
32
+ <div id="content">
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ <!-- Namespace -->
45
+ <div class="sectiontitle">Namespace</div>
46
+ <ul>
47
+
48
+ <li>
49
+ <span class="type">MODULE</span>
50
+ <a href="../../../../classes/BasicTemperature.html">BasicTemperature</a>
51
+ </li>
52
+
53
+ <li>
54
+ <span class="type">MODULE</span>
55
+ <a href="../../../../classes/BasicTemperature/Temperature/AdditionalHelpers.html">BasicTemperature::Temperature::AdditionalHelpers</a>
56
+ </li>
57
+
58
+ <li>
59
+ <span class="type">CLASS</span>
60
+ <a href="../../../../classes/BasicTemperature/Temperature.html">BasicTemperature::Temperature</a>
61
+ </li>
62
+
63
+ </ul>
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>assertions.rb</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
+ </head>
14
+
15
+ <body>
16
+ <div class="banner">
17
+
18
+ <h1>
19
+ assertions.rb
20
+ </h1>
21
+ <ul class="files">
22
+
23
+ <li>
24
+ lib/basic_temperature/temperature/assertions.rb
25
+
26
+ </li>
27
+ <li>Last modified: 2020-04-16 17:45:21 +0300</li>
28
+ </ul>
29
+ </div>
30
+
31
+ <div id="bodyContent">
32
+ <div id="content">
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+ <!-- Namespace -->
45
+ <div class="sectiontitle">Namespace</div>
46
+ <ul>
47
+
48
+ <li>
49
+ <span class="type">MODULE</span>
50
+ <a href="../../../../classes/BasicTemperature.html">BasicTemperature</a>
51
+ </li>
52
+
53
+ <li>
54
+ <span class="type">MODULE</span>
55
+ <a href="../../../../classes/BasicTemperature/Temperature/Assertions.html">BasicTemperature::Temperature::Assertions</a>
56
+ </li>
57
+
58
+ <li>
59
+ <span class="type">CLASS</span>
60
+ <a href="../../../../classes/BasicTemperature/Temperature.html">BasicTemperature::Temperature</a>
61
+ </li>
62
+
63
+ </ul>
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>