basic_temperature 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,1239 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>BasicTemperature::Temperature</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::Temperature">
15
+
16
+
17
+
18
+ <meta name="description" content="Temperature is a simple Value Object for basic temperature operations like conversions from Celsius to Fahrenhait or Kelvin etc. Supported scales: Celsius, Fahrenheit, Kelvin and Rankine.">
19
+ <meta property="og:description" content="Temperature is a simple Value Object for basic temperature operations like conversions from Celsius to Fahrenhait or Kelvin etc. Supported scales: Celsius, Fahrenheit, Kelvin and Rankine.">
20
+
21
+
22
+ <meta name="keywords" content="BasicTemperature::Temperature class">
23
+
24
+ <meta name="keywords" content="[], new, set_degrees, set_scale, to_scale, to_celsius, to_fahrenheit, to_kelvin, to_rankine, <=>, boil_water?, freeze_water?">
25
+
26
+ </head>
27
+
28
+ <body>
29
+ <div class="banner">
30
+
31
+ <h1>
32
+ <span class="type">Class</span>
33
+ BasicTemperature::Temperature
34
+
35
+ <span class="parent">&lt;
36
+
37
+ <a href="../Object.html">Object</a>
38
+
39
+ </span>
40
+
41
+ </h1>
42
+ <ul class="files">
43
+
44
+ <li><a href="../../files/lib/basic_temperature/temperature_rb.html">lib/basic_temperature/temperature.rb</a></li>
45
+
46
+ <li><a href="../../files/lib/basic_temperature/temperature/additional_helpers_rb.html">lib/basic_temperature/temperature/additional_helpers.rb</a></li>
47
+
48
+ <li><a href="../../files/lib/basic_temperature/temperature/assertions_rb.html">lib/basic_temperature/temperature/assertions.rb</a></li>
49
+
50
+ <li><a href="../../files/lib/basic_temperature/temperature/casting_rb.html">lib/basic_temperature/temperature/casting.rb</a></li>
51
+
52
+ <li><a href="../../files/lib/basic_temperature/temperature/errors_rb.html">lib/basic_temperature/temperature/errors.rb</a></li>
53
+
54
+ <li><a href="../../files/lib/basic_temperature/temperature/initialization_rb.html">lib/basic_temperature/temperature/initialization.rb</a></li>
55
+
56
+ <li><a href="../../files/lib/basic_temperature/temperature/memoization_rb.html">lib/basic_temperature/temperature/memoization.rb</a></li>
57
+
58
+ <li><a href="../../files/lib/basic_temperature/temperature/rounding_rb.html">lib/basic_temperature/temperature/rounding.rb</a></li>
59
+
60
+ </ul>
61
+ </div>
62
+ <div id="bodyContent">
63
+ <div id="content">
64
+
65
+ <div class="description">
66
+
67
+ <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>
68
+
69
+ <p>Supported scales: <code>Celsius</code>, <code>Fahrenheit</code>, <code>Kelvin</code> and <code>Rankine</code>.</p>
70
+
71
+ <h2 id="class-BasicTemperature::Temperature-label-Creating+Temperatures">Creating Temperatures</h2>
72
+
73
+ <p>A new temperature can be created in multiple ways:</p>
74
+ <ul><li>
75
+ <p>Using keyword arguments:</p>
76
+
77
+ <pre><code>Temperature.new(degrees: 0, scale: :celsius)
78
+ </code></pre>
79
+ </li><li>
80
+ <p>Using positional arguments:</p>
81
+
82
+ <pre><code>Temperature.new(0, :celsius)
83
+ </code></pre>
84
+ </li><li>
85
+ <p>Even more concise way using <code>Temperature.[]</code> (an alias of <code>Temperature.new</code>):</p>
86
+
87
+ <pre><code>Temperature[0, :celsius]
88
+ </code></pre>
89
+ </li></ul>
90
+
91
+ <h2 id="class-BasicTemperature::Temperature-label-Creating+Temperatures+from+already+existing+temperature+objects">Creating Temperatures from already existing temperature objects</h2>
92
+
93
+ <p>Sometimes it is useful to create a new temperature from already existing one.</p>
94
+
95
+ <p>For such cases, there are <a href="Temperature.html#method-i-set_degrees">set_degrees</a> and <a href="Temperature.html#method-i-set_scale">set_scale</a>.</p>
96
+
97
+ <p>Since temperatures are <a href="https://martinfowler.com/bliki/ValueObject.html">Value Objects</a>, both methods returns new instances.</p>
98
+
99
+ <p>Examples:</p>
100
+
101
+ <pre><code>temperature = Temperature[0, :celsius]
102
+ # =&gt; 0 °C
103
+
104
+ new_temperature = temperature.set_degrees(15)
105
+ # =&gt; 15 °C
106
+
107
+ temperature = Temperature[0, :celsius]
108
+ # =&gt; 0 °C
109
+
110
+ new_temperature = temperature.set_scale(:kelvin)
111
+ # =&gt; 0 K
112
+ </code></pre>
113
+
114
+ <h2 id="class-BasicTemperature::Temperature-label-Conversions">Conversions</h2>
115
+
116
+ <p>Temperatures can be converted to diffirent scales.</p>
117
+
118
+ <p>Currently, the following scales are supported: <code>Celsius</code>, <code>Fahrenheit</code>, <code>Kelvin</code> and <code>Rankine</code>.</p>
119
+
120
+ <pre><code>Temperature[20, :celsius].to_celsius
121
+ # =&gt; 20 °C
122
+
123
+ Temperature[20, :celsius].to_fahrenheit
124
+ # =&gt; 68 °F
125
+
126
+ Temperature[20, :celsius].to_kelvin
127
+ # =&gt; 293.15 K
128
+
129
+ Temperature[20, :celsius].to_rankine
130
+ # =&gt; 527.67 °R
131
+ </code></pre>
132
+
133
+ <p>If it is necessary to convert scale dynamically, <a href="Temperature.html#method-i-to_scale">to_scale</a> method is available.</p>
134
+
135
+ <pre><code>Temperature[20, :celsius].to_scale(scale)
136
+ </code></pre>
137
+
138
+ <p>All conversion formulas are taken from <a href="https://www.rapidtables.com/convert/temperature/index.html">RapidTables</a>.</p>
139
+
140
+ <p>Conversion precision: 2 accurate digits after the decimal dot.</p>
141
+
142
+ <h2 id="class-BasicTemperature::Temperature-label-Comparison">Comparison</h2>
143
+
144
+ <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>
145
+
146
+ <p>As a result, all methods from Comparable are available, e.g:</p>
147
+
148
+ <pre><code>Temperature[20, :celsius] &lt; Temperature[25, :celsius]
149
+ # =&gt; true
150
+
151
+ Temperature[20, :celsius] &lt;= Temperature[25, :celsius]
152
+ # =&gt; true
153
+
154
+ Temperature[20, :celsius] == Temperature[25, :celsius]
155
+ # =&gt; false
156
+
157
+ Temperature[20, :celsius] &gt; Temperature[25, :celsius]
158
+ # =&gt; false
159
+
160
+ Temperature[20, :celsius] &gt;= Temperature[25, :celsius]
161
+ # =&gt; false
162
+
163
+ Temperature[20, :celsius].between?(Temperature[15, :celsius], Temperature[25, :celsius])
164
+ # =&gt; true
165
+
166
+ # Starting from Ruby 2.4.6
167
+ Temperature[20, :celsius].clamp(Temperature[20, :celsius], Temperature[25, :celsius])
168
+ # =&gt; 20 °C
169
+ </code></pre>
170
+
171
+ <p>Please note, if <code>other</code> temperature has a different scale, temperature is automatically converted to that scale before comparison.</p>
172
+
173
+ <pre><code>Temperature[20, :celsius] == Temperature[293.15, :kelvin]
174
+ # =&gt; true
175
+ </code></pre>
176
+
177
+ <p>IMPORTANT !!!</p>
178
+
179
+ <p><code>degrees</code> are rounded to the nearest value with a precision of 2 decimal digits before comparison.</p>
180
+
181
+ <p>This means the following temperatures are considered as equal:</p>
182
+
183
+ <pre><code>Temperature[20.020, :celsius] == Temperature[20.024, :celsius]
184
+ # =&gt; true
185
+
186
+ Temperature[20.025, :celsius] == Temperature[20.029, :celsius]
187
+ # =&gt; true
188
+ </code></pre>
189
+
190
+ <p>while these ones are treated as NOT equal:</p>
191
+
192
+ <pre><code>Temperature[20.024, :celsius] == Temperature[20.029, :celsius]
193
+ # =&gt; false
194
+ </code></pre>
195
+
196
+ <h2 id="class-BasicTemperature::Temperature-label-Math">Math</h2>
197
+
198
+ <h4 id="class-BasicTemperature::Temperature-label-Addition-2FSubtraction.">Addition/Subtraction.</h4>
199
+
200
+ <pre><code>Temperature[20, :celsius] + Temperature[10, :celsius]
201
+ # =&gt; 30 °C
202
+
203
+ Temperature[20, :celsius] - Temperature[10, :celsius]
204
+ # =&gt; 10 °C
205
+ </code></pre>
206
+
207
+ <p>If second temperature has a different scale, first temperature is automatically converted to that scale before <code>degrees</code> addition/subtraction.</p>
208
+
209
+ <pre><code>Temperature[283.15, :kelvin] + Temperature[10, :celsius]
210
+ # =&gt; 10 °C
211
+ </code></pre>
212
+
213
+ <p>Returned temperature will have the same scale as the second temperature.</p>
214
+
215
+ <p>It is possible to add/subtract numerics.</p>
216
+
217
+ <pre><code>Temperature[20, :celsius] + 10
218
+ # =&gt; 30 °C
219
+
220
+ Temperature[20, :celsius] - 10
221
+ # =&gt; 10 °C
222
+ </code></pre>
223
+
224
+ <p>In such cases, returned temperature will have the same scale as the first temperature.</p>
225
+
226
+ <p>Also <a href="https://ruby-doc.org/core/Numeric.html#method-i-coerce">Ruby coersion mechanism</a> is supported.</p>
227
+
228
+ <pre><code>10 + Temperature[20, :celsius]
229
+ # =&gt; 30 °C
230
+
231
+ 10 - Temperature[20, :celsius]
232
+ # =&gt; -10 °C
233
+ </code></pre>
234
+
235
+ <h4 id="class-BasicTemperature::Temperature-label-Negation">Negation</h4>
236
+
237
+ <pre><code>-Temperature[20, :celsius]
238
+ # =&gt; -20 °C
239
+ </code></pre>
240
+
241
+ <h2 id="class-BasicTemperature::Temperature-label-Queries">Queries</h2>
242
+
243
+ <pre><code>Temperature[0, :celsius].boil_water?
244
+ # =&gt; false
245
+
246
+ Temperature[0, :celsius].freeze_water?
247
+ # =&gt; true
248
+ </code></pre>
249
+
250
+ </div>
251
+
252
+
253
+
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+
262
+ <!-- Namespace -->
263
+ <div class="sectiontitle">Namespace</div>
264
+ <ul>
265
+
266
+ <li>
267
+ <span class="type">MODULE</span>
268
+ <a href="Temperature/AdditionalHelpers.html">BasicTemperature::Temperature::AdditionalHelpers</a>
269
+ </li>
270
+
271
+ <li>
272
+ <span class="type">MODULE</span>
273
+ <a href="Temperature/Assertions.html">BasicTemperature::Temperature::Assertions</a>
274
+ </li>
275
+
276
+ <li>
277
+ <span class="type">MODULE</span>
278
+ <a href="Temperature/Casting.html">BasicTemperature::Temperature::Casting</a>
279
+ </li>
280
+
281
+ <li>
282
+ <span class="type">MODULE</span>
283
+ <a href="Temperature/Errors.html">BasicTemperature::Temperature::Errors</a>
284
+ </li>
285
+
286
+ <li>
287
+ <span class="type">MODULE</span>
288
+ <a href="Temperature/Initialization.html">BasicTemperature::Temperature::Initialization</a>
289
+ </li>
290
+
291
+ <li>
292
+ <span class="type">MODULE</span>
293
+ <a href="Temperature/Memoization.html">BasicTemperature::Temperature::Memoization</a>
294
+ </li>
295
+
296
+ <li>
297
+ <span class="type">MODULE</span>
298
+ <a href="Temperature/Rounding.html">BasicTemperature::Temperature::Rounding</a>
299
+ </li>
300
+
301
+ </ul>
302
+
303
+
304
+
305
+
306
+ <!-- Method ref -->
307
+ <div class="sectiontitle">Methods</div>
308
+ <dl class="methods">
309
+
310
+ <dt>#</dt>
311
+ <dd>
312
+ <ul>
313
+
314
+
315
+ <li>
316
+ <a href="#method-i-3C-3D-3E">&lt;=&gt;</a>,
317
+ </li>
318
+
319
+
320
+ <li>
321
+ <a href="#method-c-5B-5D">[]</a>
322
+ </li>
323
+
324
+ </ul>
325
+ </dd>
326
+
327
+ <dt>B</dt>
328
+ <dd>
329
+ <ul>
330
+
331
+
332
+ <li>
333
+ <a href="#method-i-boil_water-3F">boil_water?</a>
334
+ </li>
335
+
336
+ </ul>
337
+ </dd>
338
+
339
+ <dt>F</dt>
340
+ <dd>
341
+ <ul>
342
+
343
+
344
+ <li>
345
+ <a href="#method-i-freeze_water-3F">freeze_water?</a>
346
+ </li>
347
+
348
+ </ul>
349
+ </dd>
350
+
351
+ <dt>N</dt>
352
+ <dd>
353
+ <ul>
354
+
355
+
356
+ <li>
357
+ <a href="#method-c-new">new</a>
358
+ </li>
359
+
360
+ </ul>
361
+ </dd>
362
+
363
+ <dt>S</dt>
364
+ <dd>
365
+ <ul>
366
+
367
+
368
+ <li>
369
+ <a href="#method-i-set_degrees">set_degrees</a>,
370
+ </li>
371
+
372
+
373
+ <li>
374
+ <a href="#method-i-set_scale">set_scale</a>
375
+ </li>
376
+
377
+ </ul>
378
+ </dd>
379
+
380
+ <dt>T</dt>
381
+ <dd>
382
+ <ul>
383
+
384
+
385
+ <li>
386
+ <a href="#method-i-to_celsius">to_celsius</a>,
387
+ </li>
388
+
389
+
390
+ <li>
391
+ <a href="#method-i-to_fahrenheit">to_fahrenheit</a>,
392
+ </li>
393
+
394
+
395
+ <li>
396
+ <a href="#method-i-to_kelvin">to_kelvin</a>,
397
+ </li>
398
+
399
+
400
+ <li>
401
+ <a href="#method-i-to_rankine">to_rankine</a>,
402
+ </li>
403
+
404
+
405
+ <li>
406
+ <a href="#method-i-to_scale">to_scale</a>
407
+ </li>
408
+
409
+ </ul>
410
+ </dd>
411
+
412
+ </dl>
413
+
414
+
415
+
416
+ <!-- Includes -->
417
+ <div class="sectiontitle">Included Modules</div>
418
+ <ul>
419
+
420
+ <li>
421
+
422
+ Comparable
423
+
424
+ </li>
425
+
426
+ <li>
427
+
428
+ <a href="Temperature/AdditionalHelpers.html">
429
+ BasicTemperature::Temperature::AdditionalHelpers
430
+ </a>
431
+
432
+ </li>
433
+
434
+ <li>
435
+
436
+ <a href="Temperature/Assertions.html">
437
+ BasicTemperature::Temperature::Assertions
438
+ </a>
439
+
440
+ </li>
441
+
442
+ <li>
443
+
444
+ <a href="Temperature/Casting.html">
445
+ BasicTemperature::Temperature::Casting
446
+ </a>
447
+
448
+ </li>
449
+
450
+ <li>
451
+
452
+ <a href="Temperature/Errors.html">
453
+ BasicTemperature::Temperature::Errors
454
+ </a>
455
+
456
+ </li>
457
+
458
+ <li>
459
+
460
+ <a href="Temperature/Initialization.html">
461
+ BasicTemperature::Temperature::Initialization
462
+ </a>
463
+
464
+ </li>
465
+
466
+ <li>
467
+
468
+ <a href="Temperature/Memoization.html">
469
+ BasicTemperature::Temperature::Memoization
470
+ </a>
471
+
472
+ </li>
473
+
474
+ <li>
475
+
476
+ <a href="Temperature/Rounding.html">
477
+ BasicTemperature::Temperature::Rounding
478
+ </a>
479
+
480
+ </li>
481
+
482
+ </ul>
483
+
484
+
485
+
486
+
487
+
488
+
489
+
490
+
491
+
492
+
493
+
494
+ <!-- Section constants -->
495
+ <div class="sectiontitle">Constants</div>
496
+ <table border='0' cellpadding='5'>
497
+
498
+ <tr valign='top'>
499
+ <td class="attr-name">CELSIUS</td>
500
+ <td>=</td>
501
+ <td class="attr-value">&#39;celsius&#39;</td>
502
+ </tr>
503
+
504
+ <tr valign='top'>
505
+ <td>&nbsp;</td>
506
+ <td colspan="2" class="attr-desc"></td>
507
+ </tr>
508
+
509
+
510
+ <tr valign='top'>
511
+ <td class="attr-name">FAHRENHEIT</td>
512
+ <td>=</td>
513
+ <td class="attr-value">&#39;fahrenheit&#39;</td>
514
+ </tr>
515
+
516
+ <tr valign='top'>
517
+ <td>&nbsp;</td>
518
+ <td colspan="2" class="attr-desc"></td>
519
+ </tr>
520
+
521
+
522
+ <tr valign='top'>
523
+ <td class="attr-name">KELVIN</td>
524
+ <td>=</td>
525
+ <td class="attr-value">&#39;kelvin&#39;</td>
526
+ </tr>
527
+
528
+ <tr valign='top'>
529
+ <td>&nbsp;</td>
530
+ <td colspan="2" class="attr-desc"></td>
531
+ </tr>
532
+
533
+
534
+ <tr valign='top'>
535
+ <td class="attr-name">RANKINE</td>
536
+ <td>=</td>
537
+ <td class="attr-value">&#39;rankine&#39;</td>
538
+ </tr>
539
+
540
+ <tr valign='top'>
541
+ <td>&nbsp;</td>
542
+ <td colspan="2" class="attr-desc"></td>
543
+ </tr>
544
+
545
+
546
+ <tr valign='top'>
547
+ <td class="attr-name">SCALES</td>
548
+ <td>=</td>
549
+ <td class="attr-value">[CELSIUS, FAHRENHEIT, KELVIN, RANKINE].freeze</td>
550
+ </tr>
551
+
552
+ <tr valign='top'>
553
+ <td>&nbsp;</td>
554
+ <td colspan="2" class="attr-desc"><p>A list of all currently supported scale values.</p></td>
555
+ </tr>
556
+
557
+
558
+ </table>
559
+
560
+
561
+
562
+
563
+ <!-- Section attributes -->
564
+ <div class="sectiontitle">Attributes</div>
565
+ <table border='0' cellpadding='5'>
566
+
567
+ <tr valign='top'>
568
+ <td class='attr-rw'>
569
+ [R]
570
+ </td>
571
+ <td class='attr-name'>degrees</td>
572
+ <td class='attr-desc'><p>Degrees of the temperature.</p></td>
573
+ </tr>
574
+
575
+ <tr valign='top'>
576
+ <td class='attr-rw'>
577
+ [R]
578
+ </td>
579
+ <td class='attr-name'>scale</td>
580
+ <td class='attr-desc'><p>Scale of the temperature. Look at SCALES for possible values.</p></td>
581
+ </tr>
582
+
583
+ </table>
584
+
585
+
586
+
587
+ <!-- Methods -->
588
+
589
+ <div class="sectiontitle">Class Public methods</div>
590
+
591
+ <div class="method">
592
+ <div class="title method-title" id="method-c-5B-5D">
593
+
594
+ <b>[](degrees:, scale:)<br />[](degrees, scale)</b>
595
+
596
+ <a href="../../classes/BasicTemperature/Temperature.html#method-c-5B-5D" name="method-c-5B-5D" class="permalink">Link</a>
597
+ </div>
598
+
599
+
600
+ <div class="description">
601
+ <p>Creates a new instance of <a href="Temperature.html"><code>Temperature</code></a>. Alias for <code>new</code>.</p>
602
+ </div>
603
+
604
+
605
+
606
+
607
+
608
+
609
+
610
+
611
+ <div class="sourcecode">
612
+
613
+ <p class="source-link">
614
+ Source:
615
+ <a href="javascript:toggleSource('method-c-5B-5D_source')" id="l_method-c-5B-5D_source">show</a>
616
+
617
+ </p>
618
+ <div id="method-c-5B-5D_source" class="dyn-source">
619
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 224</span>
620
+ <span class="ruby-keyword">def</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier ruby-title">[]</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>)
621
+ <span class="ruby-identifier">new</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">args</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">kwargs</span>)
622
+ <span class="ruby-keyword">end</span></pre>
623
+ </div>
624
+ </div>
625
+
626
+ </div>
627
+
628
+ <div class="method">
629
+ <div class="title method-title" id="method-c-new">
630
+
631
+ <b>new(degrees:, scale:)<br />new(degrees, scale)</b>
632
+
633
+ <a href="../../classes/BasicTemperature/Temperature.html#method-c-new" name="method-c-new" class="permalink">Link</a>
634
+ </div>
635
+
636
+
637
+ <div class="description">
638
+ <p>Creates a new instance of <a href="Temperature.html"><code>Temperature</code></a>. Is aliased as <code>[]</code>.</p>
639
+ </div>
640
+
641
+
642
+
643
+
644
+
645
+
646
+
647
+
648
+ <div class="sourcecode">
649
+
650
+ <p class="source-link">
651
+ Source:
652
+ <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
653
+
654
+ </p>
655
+ <div id="method-c-new_source" class="dyn-source">
656
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 235</span>
657
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-operator">*</span><span class="ruby-identifier">positional_arguments</span>, <span class="ruby-operator">**</span><span class="ruby-identifier">keyword_arguments</span>)
658
+ <span class="ruby-identifier">assert_either_positional_arguments_or_keyword_arguments!</span>(<span class="ruby-identifier">positional_arguments</span>, <span class="ruby-identifier">keyword_arguments</span>)
659
+
660
+ <span class="ruby-keyword">if</span> <span class="ruby-identifier">keyword_arguments</span>.<span class="ruby-identifier">any?</span>
661
+ <span class="ruby-identifier">initialize_via_keywords_arguments</span>(<span class="ruby-identifier">keyword_arguments</span>)
662
+ <span class="ruby-keyword">else</span> <span class="ruby-comment"># positional_arguments.any?</span>
663
+ <span class="ruby-identifier">initialize_via_positional_arguments</span>(<span class="ruby-identifier">positional_arguments</span>)
664
+ <span class="ruby-keyword">end</span>
665
+ <span class="ruby-keyword">end</span></pre>
666
+ </div>
667
+ </div>
668
+
669
+ </div>
670
+
671
+
672
+
673
+ <div class="sectiontitle">Instance Public methods</div>
674
+
675
+ <div class="method">
676
+ <div class="title method-title" id="method-i-3C-3D-3E">
677
+
678
+ <b>&lt;=&gt;</b>(other)
679
+
680
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-3C-3D-3E" name="method-i-3C-3D-3E" class="permalink">Link</a>
681
+ </div>
682
+
683
+
684
+ <div class="description">
685
+ <p>Compares temperture with <code>other</code> temperature.</p>
686
+
687
+ <p>Returns <code>0</code> if they are considered as equal.</p>
688
+
689
+ <p>Two temperatures are considered as equal when they have the same amount of <code>degrees</code>.</p>
690
+
691
+ <p>Returns <code>-1</code> if temperature is lower than <code>other</code> temperature.</p>
692
+
693
+ <p>Returns <code>1</code> if temperature is higher than <code>other</code> temperature.</p>
694
+
695
+ <p>If <code>other</code> temperature has a different scale, temperature is automatically converted to that scale before <code>degrees</code> comparison.</p>
696
+
697
+ <pre><code>Temperature[20, :celsius] &lt;=&gt; Temperature[20, :celsius]
698
+ # =&gt; 0
699
+
700
+ Temperature[20, :celsius] &lt;=&gt; Temperature[293.15, :kelvin]
701
+ # =&gt; 0
702
+ </code></pre>
703
+
704
+ <p>IMPORTANT!!!</p>
705
+
706
+ <p>This method rounds <code>degrees</code> to the nearest value with a precision of 2 decimal digits.</p>
707
+
708
+ <p>This means the following:</p>
709
+
710
+ <pre><code>Temperature[20.020, :celsius] &lt;=&gt; Temperature[20.024, :celsius]
711
+ # =&gt; 0
712
+
713
+ Temperature[20.025, :celsius] &lt;=&gt; Temperature[20.029, :celsius]
714
+ # =&gt; 0
715
+
716
+ Temperature[20.024, :celsius] &lt;=&gt; Temperature[20.029, :celsius]
717
+ # =&gt; -1
718
+ </code></pre>
719
+ </div>
720
+
721
+
722
+
723
+
724
+
725
+
726
+
727
+
728
+ <div class="sourcecode">
729
+
730
+ <p class="source-link">
731
+ Source:
732
+ <a href="javascript:toggleSource('method-i-3C-3D-3E_source')" id="l_method-i-3C-3D-3E_source">show</a>
733
+
734
+ </p>
735
+ <div id="method-i-3C-3D-3E_source" class="dyn-source">
736
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 466</span>
737
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">&lt;=&gt;</span>(<span class="ruby-identifier">other</span>)
738
+ <span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">assert_temperature</span>(<span class="ruby-identifier">other</span>)
739
+
740
+ <span class="ruby-identifier">round_degrees</span>(<span class="ruby-keyword">self</span>.<span class="ruby-identifier">to_scale</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">scale</span>).<span class="ruby-identifier">degrees</span>) <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">round_degrees</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">degrees</span>)
741
+ <span class="ruby-keyword">end</span></pre>
742
+ </div>
743
+ </div>
744
+
745
+ </div>
746
+
747
+ <div class="method">
748
+ <div class="title method-title" id="method-i-boil_water-3F">
749
+
750
+ <b>boil_water?</b>()
751
+
752
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-boil_water-3F" name="method-i-boil_water-3F" class="permalink">Link</a>
753
+ </div>
754
+
755
+
756
+ <div class="description">
757
+ <p>Returns true when temperature boils water (is greater than or equal to 100 °C), false otherwise.</p>
758
+ </div>
759
+
760
+
761
+
762
+
763
+
764
+
765
+
766
+
767
+ <div class="sourcecode">
768
+
769
+ <p class="source-link">
770
+ Source:
771
+ <a href="javascript:toggleSource('method-i-boil_water-3F_source')" id="l_method-i-boil_water-3F_source">show</a>
772
+
773
+ </p>
774
+ <div id="method-i-boil_water-3F_source" class="dyn-source">
775
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 476</span>
776
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">boil_water?</span>
777
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">to_celsius</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">100</span>
778
+ <span class="ruby-keyword">end</span></pre>
779
+ </div>
780
+ </div>
781
+
782
+ </div>
783
+
784
+ <div class="method">
785
+ <div class="title method-title" id="method-i-freeze_water-3F">
786
+
787
+ <b>freeze_water?</b>()
788
+
789
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-freeze_water-3F" name="method-i-freeze_water-3F" class="permalink">Link</a>
790
+ </div>
791
+
792
+
793
+ <div class="description">
794
+ <p>Returns true when temperature freezes water (is less than or equal to 0 °C), false otherwise.</p>
795
+ </div>
796
+
797
+
798
+
799
+
800
+
801
+
802
+
803
+
804
+ <div class="sourcecode">
805
+
806
+ <p class="source-link">
807
+ Source:
808
+ <a href="javascript:toggleSource('method-i-freeze_water-3F_source')" id="l_method-i-freeze_water-3F_source">show</a>
809
+
810
+ </p>
811
+ <div id="method-i-freeze_water-3F_source" class="dyn-source">
812
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 484</span>
813
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">freeze_water?</span>
814
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">to_celsius</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">0</span>
815
+ <span class="ruby-keyword">end</span></pre>
816
+ </div>
817
+ </div>
818
+
819
+ </div>
820
+
821
+ <div class="method">
822
+ <div class="title method-title" id="method-i-set_degrees">
823
+
824
+ <b>set_degrees</b>(degrees)
825
+
826
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-set_degrees" name="method-i-set_degrees" class="permalink">Link</a>
827
+ </div>
828
+
829
+
830
+ <div class="description">
831
+ <p>Returns a new <a href="Temperature.html"><code>Temperature</code></a> with updated <code>degrees</code>.</p>
832
+
833
+ <pre><code>temperature = Temperature[0, :celsius]
834
+ # =&gt; 0 °C
835
+
836
+ new_temperature = temperature.set_degrees(15)
837
+ # =&gt; 15 °C
838
+ </code></pre>
839
+ </div>
840
+
841
+
842
+
843
+
844
+
845
+
846
+
847
+
848
+ <div class="sourcecode">
849
+
850
+ <p class="source-link">
851
+ Source:
852
+ <a href="javascript:toggleSource('method-i-set_degrees_source')" id="l_method-i-set_degrees_source">show</a>
853
+
854
+ </p>
855
+ <div id="method-i-set_degrees_source" class="dyn-source">
856
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 255</span>
857
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_degrees</span>(<span class="ruby-identifier">degrees</span>)
858
+ <span class="ruby-constant">Temperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span>)
859
+ <span class="ruby-keyword">end</span></pre>
860
+ </div>
861
+ </div>
862
+
863
+ </div>
864
+
865
+ <div class="method">
866
+ <div class="title method-title" id="method-i-set_scale">
867
+
868
+ <b>set_scale</b>(scale)
869
+
870
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-set_scale" name="method-i-set_scale" class="permalink">Link</a>
871
+ </div>
872
+
873
+
874
+ <div class="description">
875
+ <p>Returns a new <a href="Temperature.html"><code>Temperature</code></a> with updated <code>scale</code>.</p>
876
+
877
+ <pre><code>temperature = Temperature[0, :celsius]
878
+ # =&gt; 0 °C
879
+
880
+ new_temperature = temperature.set_scale(:kelvin)
881
+ # =&gt; 0 K
882
+ </code></pre>
883
+ </div>
884
+
885
+
886
+
887
+
888
+
889
+
890
+
891
+
892
+ <div class="sourcecode">
893
+
894
+ <p class="source-link">
895
+ Source:
896
+ <a href="javascript:toggleSource('method-i-set_scale_source')" id="l_method-i-set_scale_source">show</a>
897
+
898
+ </p>
899
+ <div id="method-i-set_scale_source" class="dyn-source">
900
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 270</span>
901
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_scale</span>(<span class="ruby-identifier">scale</span>)
902
+ <span class="ruby-constant">Temperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span>)
903
+ <span class="ruby-keyword">end</span></pre>
904
+ </div>
905
+ </div>
906
+
907
+ </div>
908
+
909
+ <div class="method">
910
+ <div class="title method-title" id="method-i-to_celsius">
911
+
912
+ <b>to_celsius</b>()
913
+
914
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-to_celsius" name="method-i-to_celsius" class="permalink">Link</a>
915
+ </div>
916
+
917
+
918
+ <div class="description">
919
+ <p>Converts temperature to Celsius scale. If temperature is already in Celsius, returns current temperature object.</p>
920
+
921
+ <p>Memoizes subsequent calls.</p>
922
+
923
+ <p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
924
+ <ol><li>
925
+ <p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-fahrenheit.html">Celsius to Fahrenheit</a>.</p>
926
+ </li><li>
927
+ <p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-kelvin.html">Celsius to Kelvin</a>.</p>
928
+ </li><li>
929
+ <p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-rankine.html">Celsius to Rankine</a>.</p>
930
+ </li></ol>
931
+
932
+ <pre><code>Temperature[0, :fahrenheit].to_celsius
933
+ # =&gt; -17.78 °C
934
+ </code></pre>
935
+ </div>
936
+
937
+
938
+
939
+
940
+
941
+
942
+
943
+
944
+ <div class="sourcecode">
945
+
946
+ <p class="source-link">
947
+ Source:
948
+ <a href="javascript:toggleSource('method-i-to_celsius_source')" id="l_method-i-to_celsius_source">show</a>
949
+
950
+ </p>
951
+ <div id="method-i-to_celsius_source" class="dyn-source">
952
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 317</span>
953
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_celsius</span>
954
+ <span class="ruby-identifier">memoized</span>(<span class="ruby-value">:to_celsius</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">memoize</span>(<span class="ruby-value">:to_celsius</span>, <span class="ruby-operator">-&gt;</span> {
955
+ <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">==</span> <span class="ruby-constant">CELSIUS</span>
956
+
957
+ <span class="ruby-identifier">degrees</span> =
958
+ <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
959
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
960
+ (<span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">-</span> <span class="ruby-value">32</span>) <span class="ruby-operator">*</span> (<span class="ruby-value">5</span> <span class="ruby-operator">/</span> <span class="ruby-value">9r</span>)
961
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
962
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">-</span> <span class="ruby-value">273.15</span>
963
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
964
+ (<span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">-</span> <span class="ruby-value">491.67</span>) <span class="ruby-operator">*</span> (<span class="ruby-value">5</span> <span class="ruby-operator">/</span> <span class="ruby-value">9r</span>)
965
+ <span class="ruby-keyword">end</span>
966
+
967
+ <span class="ruby-constant">Temperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">CELSIUS</span>)
968
+ })
969
+ <span class="ruby-keyword">end</span></pre>
970
+ </div>
971
+ </div>
972
+
973
+ </div>
974
+
975
+ <div class="method">
976
+ <div class="title method-title" id="method-i-to_fahrenheit">
977
+
978
+ <b>to_fahrenheit</b>()
979
+
980
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-to_fahrenheit" name="method-i-to_fahrenheit" class="permalink">Link</a>
981
+ </div>
982
+
983
+
984
+ <div class="description">
985
+ <p>Converts temperature to Fahrenheit scale. If temperature is already in Fahrenheit, returns current temperature object.</p>
986
+
987
+ <p>Memoizes subsequent calls.</p>
988
+
989
+ <p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
990
+ <ol><li>
991
+ <p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-celsius.html">Fahrenheit to Celsius</a>.</p>
992
+ </li><li>
993
+ <p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-kelvin.html">Fahrenheit to Kelvin</a>.</p>
994
+ </li><li>
995
+ <p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-rankine.html">Fahrenheit to Rankine</a>.</p>
996
+ </li></ol>
997
+
998
+ <pre><code>Temperature[0, :celsius].to_fahrenheit
999
+ # =&gt; 32 °F
1000
+ </code></pre>
1001
+ </div>
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+ <div class="sourcecode">
1011
+
1012
+ <p class="source-link">
1013
+ Source:
1014
+ <a href="javascript:toggleSource('method-i-to_fahrenheit_source')" id="l_method-i-to_fahrenheit_source">show</a>
1015
+
1016
+ </p>
1017
+ <div id="method-i-to_fahrenheit_source" class="dyn-source">
1018
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 349</span>
1019
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_fahrenheit</span>
1020
+ <span class="ruby-identifier">memoized</span>(<span class="ruby-value">:to_fahrenheit</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">memoize</span>(<span class="ruby-value">:to_fahrenheit</span>, <span class="ruby-operator">-&gt;</span> {
1021
+ <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">==</span> <span class="ruby-constant">FAHRENHEIT</span>
1022
+
1023
+ <span class="ruby-identifier">degrees</span> =
1024
+ <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
1025
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
1026
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">*</span> (<span class="ruby-value">9</span> <span class="ruby-operator">/</span> <span class="ruby-value">5r</span>) <span class="ruby-operator">+</span> <span class="ruby-value">32</span>
1027
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
1028
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">*</span> (<span class="ruby-value">9</span> <span class="ruby-operator">/</span> <span class="ruby-value">5r</span>) <span class="ruby-operator">-</span> <span class="ruby-value">459.67</span>
1029
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
1030
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">-</span> <span class="ruby-value">459.67</span>
1031
+ <span class="ruby-keyword">end</span>
1032
+
1033
+ <span class="ruby-constant">Temperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">FAHRENHEIT</span>)
1034
+ })
1035
+ <span class="ruby-keyword">end</span></pre>
1036
+ </div>
1037
+ </div>
1038
+
1039
+ </div>
1040
+
1041
+ <div class="method">
1042
+ <div class="title method-title" id="method-i-to_kelvin">
1043
+
1044
+ <b>to_kelvin</b>()
1045
+
1046
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-to_kelvin" name="method-i-to_kelvin" class="permalink">Link</a>
1047
+ </div>
1048
+
1049
+
1050
+ <div class="description">
1051
+ <p>Converts temperature to Kelvin scale. If temperature is already in Kelvin, returns current</p>
1052
+
1053
+ <pre><code>temperature object.
1054
+ </code></pre>
1055
+
1056
+ <p>Memoizes subsequent calls.</p>
1057
+
1058
+ <p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
1059
+ <ol><li>
1060
+ <p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-celsius.html">Kelvin to Celsius</a>.</p>
1061
+ </li><li>
1062
+ <p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-fahrenheit.html">Kelvin to Fahrenheit</a>.</p>
1063
+ </li><li>
1064
+ <p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-rankine.html">Kelvin to Rankine</a>.</p>
1065
+ </li></ol>
1066
+
1067
+ <pre><code>Temperature[0, :kelvin].to_rankine
1068
+ # =&gt; 0 °R
1069
+ </code></pre>
1070
+ </div>
1071
+
1072
+
1073
+
1074
+
1075
+
1076
+
1077
+
1078
+
1079
+ <div class="sourcecode">
1080
+
1081
+ <p class="source-link">
1082
+ Source:
1083
+ <a href="javascript:toggleSource('method-i-to_kelvin_source')" id="l_method-i-to_kelvin_source">show</a>
1084
+
1085
+ </p>
1086
+ <div id="method-i-to_kelvin_source" class="dyn-source">
1087
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 381</span>
1088
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_kelvin</span>
1089
+ <span class="ruby-identifier">memoized</span>(<span class="ruby-value">:to_kelvin</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">memoize</span>(<span class="ruby-value">:to_kelvin</span>, <span class="ruby-operator">-&gt;</span> {
1090
+ <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">==</span> <span class="ruby-constant">KELVIN</span>
1091
+
1092
+ <span class="ruby-identifier">degrees</span> =
1093
+ <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
1094
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
1095
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">+</span> <span class="ruby-value">273.15</span>
1096
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
1097
+ (<span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">+</span> <span class="ruby-value">459.67</span>) <span class="ruby-operator">*</span> (<span class="ruby-value">5</span> <span class="ruby-operator">/</span> <span class="ruby-value">9r</span>)
1098
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
1099
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">*</span> (<span class="ruby-value">5</span> <span class="ruby-operator">/</span> <span class="ruby-value">9r</span>)
1100
+ <span class="ruby-keyword">end</span>
1101
+
1102
+ <span class="ruby-constant">Temperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">KELVIN</span>)
1103
+ })
1104
+ <span class="ruby-keyword">end</span></pre>
1105
+ </div>
1106
+ </div>
1107
+
1108
+ </div>
1109
+
1110
+ <div class="method">
1111
+ <div class="title method-title" id="method-i-to_rankine">
1112
+
1113
+ <b>to_rankine</b>()
1114
+
1115
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-to_rankine" name="method-i-to_rankine" class="permalink">Link</a>
1116
+ </div>
1117
+
1118
+
1119
+ <div class="description">
1120
+ <p>Converts temperature to Rankine scale. If temperature is already in Rankine, returns current temperature object.</p>
1121
+
1122
+ <p>Memoizes subsequent calls.</p>
1123
+
1124
+ <p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
1125
+ <ol><li>
1126
+ <p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-celsius.html">Rankine to Celsius</a>.</p>
1127
+ </li><li>
1128
+ <p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-fahrenheit.html">Rankine to Fahrenheit</a>.</p>
1129
+ </li><li>
1130
+ <p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-kelvin.html">Rankine to Kelvin</a>.</p>
1131
+ </li></ol>
1132
+
1133
+ <pre><code>Temperature[0, :rankine].to_kelvin
1134
+ # =&gt; 0 K
1135
+ </code></pre>
1136
+ </div>
1137
+
1138
+
1139
+
1140
+
1141
+
1142
+
1143
+
1144
+
1145
+ <div class="sourcecode">
1146
+
1147
+ <p class="source-link">
1148
+ Source:
1149
+ <a href="javascript:toggleSource('method-i-to_rankine_source')" id="l_method-i-to_rankine_source">show</a>
1150
+
1151
+ </p>
1152
+ <div id="method-i-to_rankine_source" class="dyn-source">
1153
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 413</span>
1154
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_rankine</span>
1155
+ <span class="ruby-identifier">memoized</span>(<span class="ruby-value">:to_rankine</span>) <span class="ruby-operator">||</span> <span class="ruby-identifier">memoize</span>(<span class="ruby-value">:to_rankine</span>, <span class="ruby-operator">-&gt;</span> {
1156
+ <span class="ruby-keyword">return</span> <span class="ruby-keyword">self</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span> <span class="ruby-operator">==</span> <span class="ruby-constant">RANKINE</span>
1157
+
1158
+ <span class="ruby-identifier">degrees</span> =
1159
+ <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
1160
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
1161
+ (<span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">+</span> <span class="ruby-value">273.15</span>) <span class="ruby-operator">*</span> (<span class="ruby-value">9</span> <span class="ruby-operator">/</span> <span class="ruby-value">5r</span>)
1162
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
1163
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">+</span> <span class="ruby-value">459.67</span>
1164
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
1165
+ <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">*</span> (<span class="ruby-value">9</span> <span class="ruby-operator">/</span> <span class="ruby-value">5r</span>)
1166
+ <span class="ruby-keyword">end</span>
1167
+
1168
+ <span class="ruby-constant">Temperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">RANKINE</span>)
1169
+ })
1170
+ <span class="ruby-keyword">end</span></pre>
1171
+ </div>
1172
+ </div>
1173
+
1174
+ </div>
1175
+
1176
+ <div class="method">
1177
+ <div class="title method-title" id="method-i-to_scale">
1178
+
1179
+ <b>to_scale</b>(scale)
1180
+
1181
+ <a href="../../classes/BasicTemperature/Temperature.html#method-i-to_scale" name="method-i-to_scale" class="permalink">Link</a>
1182
+ </div>
1183
+
1184
+
1185
+ <div class="description">
1186
+ <p>Converts temperature to specific <code>scale</code>. If temperature is already in desired <code>scale</code>, returns current temperature object.</p>
1187
+
1188
+ <p>Raises InvalidScaleError when <code>scale</code> can not be casted to any possible scale value (see SCALES).</p>
1189
+
1190
+ <pre><code>Temperature[60, :fahrenheit].to_scale(:celsius)
1191
+ # =&gt; 15.56 °C
1192
+ </code></pre>
1193
+ </div>
1194
+
1195
+
1196
+
1197
+
1198
+
1199
+
1200
+
1201
+
1202
+ <div class="sourcecode">
1203
+
1204
+ <p class="source-link">
1205
+ Source:
1206
+ <a href="javascript:toggleSource('method-i-to_scale_source')" id="l_method-i-to_scale_source">show</a>
1207
+
1208
+ </p>
1209
+ <div id="method-i-to_scale_source" class="dyn-source">
1210
+ <pre><span class="ruby-comment"># File lib/basic_temperature/temperature.rb, line 286</span>
1211
+ <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_scale</span>(<span class="ruby-identifier">scale</span>)
1212
+ <span class="ruby-identifier">casted_scale</span> = <span class="ruby-identifier">cast_scale</span>(<span class="ruby-identifier">scale</span>)
1213
+
1214
+ <span class="ruby-identifier">assert_valid_scale!</span>(<span class="ruby-identifier">casted_scale</span>)
1215
+
1216
+ <span class="ruby-keyword">case</span> <span class="ruby-identifier">casted_scale</span>
1217
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
1218
+ <span class="ruby-identifier">to_celsius</span>
1219
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
1220
+ <span class="ruby-identifier">to_fahrenheit</span>
1221
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
1222
+ <span class="ruby-identifier">to_kelvin</span>
1223
+ <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
1224
+ <span class="ruby-identifier">to_rankine</span>
1225
+ <span class="ruby-keyword">end</span>
1226
+ <span class="ruby-keyword">end</span></pre>
1227
+ </div>
1228
+ </div>
1229
+
1230
+ </div>
1231
+
1232
+
1233
+
1234
+
1235
+ </div>
1236
+
1237
+ </div>
1238
+ </body>
1239
+ </html>