docs/classes/BasicTemperature.html in basic_temperature-0.2.2 vs docs/classes/BasicTemperature.html in basic_temperature-1.0.0
- old
+ new
@@ -12,428 +12,94 @@
<meta property="og:title" value="BasicTemperature">
-
- <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.">
- <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.">
-
<meta name="keywords" content="BasicTemperature class">
- <meta name="keywords" content="[], new, set_degrees, set_scale, to_scale, to_celsius, to_fahrenheit, to_kelvin, to_rankine, <=>, +, -, -@">
-
</head>
<body>
<div class="banner">
<h1>
- <span class="type">Class</span>
+ <span class="type">Module</span>
BasicTemperature
- <span class="parent"><
-
- <a href="Object.html">Object</a>
-
- </span>
-
</h1>
<ul class="files">
<li><a href="../files/lib/basic_temperature_rb.html">lib/basic_temperature.rb</a></li>
+ <li><a href="../files/lib/basic_temperature/temperature_rb.html">lib/basic_temperature/temperature.rb</a></li>
+
+ <li><a href="../files/lib/basic_temperature/temperature/additional_helpers_rb.html">lib/basic_temperature/temperature/additional_helpers.rb</a></li>
+
+ <li><a href="../files/lib/basic_temperature/temperature/assertions_rb.html">lib/basic_temperature/temperature/assertions.rb</a></li>
+
+ <li><a href="../files/lib/basic_temperature/temperature/casting_rb.html">lib/basic_temperature/temperature/casting.rb</a></li>
+
+ <li><a href="../files/lib/basic_temperature/temperature/errors_rb.html">lib/basic_temperature/temperature/errors.rb</a></li>
+
+ <li><a href="../files/lib/basic_temperature/temperature/initialization_rb.html">lib/basic_temperature/temperature/initialization.rb</a></li>
+
+ <li><a href="../files/lib/basic_temperature/temperature/memoization_rb.html">lib/basic_temperature/temperature/memoization.rb</a></li>
+
+ <li><a href="../files/lib/basic_temperature/temperature/rounding_rb.html">lib/basic_temperature/temperature/rounding.rb</a></li>
+
<li><a href="../files/lib/basic_temperature/version_rb.html">lib/basic_temperature/version.rb</a></li>
</ul>
</div>
<div id="bodyContent">
<div id="content">
- <div class="description">
-
-<p><a href="BasicTemperature.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>
-<p>Supported scales: <code>Celsius</code>, <code>Fahrenheit</code>, <code>Kelvin</code> and <code>Rankine</code>.</p>
-<h2 id="class-BasicTemperature-label-Creating+Temperatures">Creating Temperatures</h2>
-
-<p>A new temperature can be created in multiple ways:</p>
-<ul><li>
-<p>Using keyword arguments:</p>
-
-<pre><code>Temperature.new(degrees: 0, scale: :celsius)
-</code></pre>
-</li><li>
-<p>Using positional arguments:</p>
-
-<pre><code>Temperature.new(0, :celsius)
-</code></pre>
-</li><li>
-<p>Even more concise way using <code>Temperature.[]</code> (an alias of <code>Temperature.new</code>):</p>
-
-<pre><code>Temperature[0, :celsius]
-</code></pre>
-</li></ul>
-
-<h2 id="class-BasicTemperature-label-Creating+Temperatures+from+already+existing+temperature+objects">Creating Temperatures from already existing temperature objects</h2>
-
-<p>Sometimes it is useful to create a new temperature from already existing one.</p>
-
-<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>
-
-<p>Since temperatures are <a href="https://martinfowler.com/bliki/ValueObject.html">Value Objects</a>, both methods returns new instances.</p>
-
-<p>Examples:</p>
-
-<pre><code>temperature = Temperature[0, :celsius]
-# => 0 °C
-
-new_temperature = temperature.set_degrees(15)
-# => 15 °C
-
-temperature = Temperature[0, :celsius]
-# => 0 °C
-
-new_temperature = temperature.set_scale(:kelvin)
-# => 0 K
-</code></pre>
-
-<h2 id="class-BasicTemperature-label-Conversions">Conversions</h2>
-
-<p>Temperatures can be converted to diffirent scales.</p>
-
-<p>Currently, the following scales are supported: <code>Celsius</code>, <code>Fahrenheit</code>, <code>Kelvin</code> and <code>Rankine</code>.</p>
-
-<pre><code>Temperature[20, :celsius].to_celsius
-# => 20 °C
-
-Temperature[20, :celsius].to_fahrenheit
-# => 68 °F
-
-Temperature[20, :celsius].to_kelvin
-# => 293.15 K
-
-Temperature[20, :celsius].to_rankine
-# => 527.67 °R
-</code></pre>
-
-<p>If it is necessary to convert scale dynamically, <a href="BasicTemperature.html#method-i-to_scale">to_scale</a> method is available.</p>
-
-<pre><code>Temperature[20, :celsius].to_scale(scale)
-</code></pre>
-
-<p>All conversion formulas are taken from <a href="https://www.rapidtables.com/convert/temperature/index.html">RapidTables</a>.</p>
-
-<p>Conversion precision: 2 accurate digits after the decimal dot.</p>
-
-<h2 id="class-BasicTemperature-label-Comparison">Comparison</h2>
-
-<p><a href="BasicTemperature.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>
-
-<p>As a result, all methods from Comparable are available, e.g:</p>
-
-<pre><code>Temperature[20, :celsius] < Temperature[25, :celsius]
-# => true
-
-Temperature[20, :celsius] <= Temperature[25, :celsius]
-# => true
-
-Temperature[20, :celsius] == Temperature[25, :celsius]
-# => false
-
-Temperature[20, :celsius] > Temperature[25, :celsius]
-# => false
-
-Temperature[20, :celsius] >= Temperature[25, :celsius]
-# => false
-
-Temperature[20, :celsius].between?(Temperature[15, :celsius], Temperature[25, :celsius])
-# => true
-
-# Starting from Ruby 2.4.6
-Temperature[20, :celsius].clamp(Temperature[20, :celsius], Temperature[25, :celsius])
-# => 20 °C
-</code></pre>
-
-<p>Please note, if <code>other</code> temperature has a different scale, temperature is automatically converted to that scale before comparison.</p>
-
-<pre><code>Temperature[20, :celsius] == Temperature[293.15, :kelvin]
-# => true
-</code></pre>
-
-<p>IMPORTANT !!!</p>
-
-<p><code>degrees</code> are rounded to the nearest value with a precision of 2 decimal digits before comparison.</p>
-
-<p>This means the following temperatures are considered as equal:</p>
-
-<pre><code>Temperature[20.020, :celsius] == Temperature[20.024, :celsius]
-# => true
-
-Temperature[20.025, :celsius] == Temperature[20.029, :celsius]
-# => true
-</code></pre>
-
-<p>while these ones are treated as NOT equal:</p>
-
-<pre><code>Temperature[20.024, :celsius] == Temperature[20.029, :celsius]
-# => false
-</code></pre>
-
-<h2 id="class-BasicTemperature-label-Math">Math</h2>
-
-<h4 id="class-BasicTemperature-label-Addition-2FSubtraction.">Addition/Subtraction.</h4>
-
-<pre><code>Temperature[20, :celsius] + Temperature[10, :celsius]
-# => 30 °C
-
-Temperature[20, :celsius] - Temperature[10, :celsius]
-# => 10 °C
-</code></pre>
-
-<p>If second temperature has a different scale, first temperature is automatically converted to that scale before <code>degrees</code> addition/subtraction.</p>
-
-<pre><code>Temperature[283.15, :kelvin] + Temperature[10, :celsius]
-# => 10 °C
-</code></pre>
-
-<p>Returned temperature will have the same scale as the second temperature.</p>
-
-<p>It is possible to add/subtract numerics.</p>
-
-<pre><code>Temperature[20, :celsius] + 10
-# => 30 °C
-
-Temperature[20, :celsius] - 10
-# => 10 °C
-</code></pre>
-
-<p>In such cases, returned temperature will have the same scale as the first temperature.</p>
-
-<p>Also <a href="https://ruby-doc.org/core/Numeric.html#method-i-coerce">Ruby coersion mechanism</a> is supported.</p>
-
-<pre><code>10 + Temperature[20, :celsius]
-# => 30 °C
-
-10 - Temperature[20, :celsius]
-# => -10 °C
-</code></pre>
-
-<h4 id="class-BasicTemperature-label-Negation">Negation</h4>
-
-<pre><code>-Temperature[20, :celsius]
-# => -20 °C
-</code></pre>
-
- </div>
-
-
-
-
-
-
- <!-- Method ref -->
- <div class="sectiontitle">Methods</div>
- <dl class="methods">
-
- <dt>#</dt>
- <dd>
- <ul>
-
-
- <li>
- <a href="#method-i-2B">+</a>,
- </li>
-
-
- <li>
- <a href="#method-i-2D">-</a>,
- </li>
-
-
- <li>
- <a href="#method-i-2D-40">-@</a>,
- </li>
-
-
- <li>
- <a href="#method-i-3C-3D-3E"><=></a>,
- </li>
-
-
- <li>
- <a href="#method-c-5B-5D">[]</a>
- </li>
-
- </ul>
- </dd>
-
- <dt>N</dt>
- <dd>
- <ul>
-
-
- <li>
- <a href="#method-c-new">new</a>
- </li>
-
- </ul>
- </dd>
-
- <dt>S</dt>
- <dd>
- <ul>
-
-
- <li>
- <a href="#method-i-set_degrees">set_degrees</a>,
- </li>
-
-
- <li>
- <a href="#method-i-set_scale">set_scale</a>
- </li>
-
- </ul>
- </dd>
-
- <dt>T</dt>
- <dd>
- <ul>
-
-
- <li>
- <a href="#method-i-to_celsius">to_celsius</a>,
- </li>
-
-
- <li>
- <a href="#method-i-to_fahrenheit">to_fahrenheit</a>,
- </li>
-
-
- <li>
- <a href="#method-i-to_kelvin">to_kelvin</a>,
- </li>
-
-
- <li>
- <a href="#method-i-to_rankine">to_rankine</a>,
- </li>
-
-
- <li>
- <a href="#method-i-to_scale">to_scale</a>
- </li>
-
- </ul>
- </dd>
-
- </dl>
-
-
-
- <!-- Includes -->
- <div class="sectiontitle">Included Modules</div>
+ <!-- Namespace -->
+ <div class="sectiontitle">Namespace</div>
<ul>
<li>
-
- Comparable
-
+ <span class="type">CLASS</span>
+ <a href="BasicTemperature/Temperature.html">BasicTemperature::Temperature</a>
</li>
</ul>
+
+
+
+
+
<!-- Section constants -->
<div class="sectiontitle">Constants</div>
<table border='0' cellpadding='5'>
<tr valign='top'>
- <td class="attr-name">CELSIUS</td>
- <td>=</td>
- <td class="attr-value">'celsius'</td>
- </tr>
-
- <tr valign='top'>
- <td> </td>
- <td colspan="2" class="attr-desc"></td>
- </tr>
-
-
- <tr valign='top'>
- <td class="attr-name">FAHRENHEIT</td>
- <td>=</td>
- <td class="attr-value">'fahrenheit'</td>
- </tr>
-
- <tr valign='top'>
- <td> </td>
- <td colspan="2" class="attr-desc"></td>
- </tr>
-
-
- <tr valign='top'>
- <td class="attr-name">KELVIN</td>
- <td>=</td>
- <td class="attr-value">'kelvin'</td>
- </tr>
-
- <tr valign='top'>
- <td> </td>
- <td colspan="2" class="attr-desc"></td>
- </tr>
-
-
- <tr valign='top'>
- <td class="attr-name">RANKINE</td>
- <td>=</td>
- <td class="attr-value">'rankine'</td>
- </tr>
-
- <tr valign='top'>
- <td> </td>
- <td colspan="2" class="attr-desc"></td>
- </tr>
-
-
- <tr valign='top'>
- <td class="attr-name">SCALES</td>
- <td>=</td>
- <td class="attr-value">[CELSIUS, FAHRENHEIT, KELVIN, RANKINE].freeze</td>
- </tr>
-
- <tr valign='top'>
- <td> </td>
- <td colspan="2" class="attr-desc"><p>A list of all currently supported scale values.</p></td>
- </tr>
-
-
- <tr valign='top'>
<td class="attr-name">VERSION</td>
<td>=</td>
- <td class="attr-value">'0.2.1'</td>
+ <td class="attr-value">'0.2.2'</td>
</tr>
<tr valign='top'>
<td> </td>
<td colspan="2" class="attr-desc"></td>
@@ -443,782 +109,14 @@
</table>
- <!-- Section attributes -->
- <div class="sectiontitle">Attributes</div>
- <table border='0' cellpadding='5'>
-
- <tr valign='top'>
- <td class='attr-rw'>
- [R]
- </td>
- <td class='attr-name'>degrees</td>
- <td class='attr-desc'><p>Degrees of the temperature.</p></td>
- </tr>
-
- <tr valign='top'>
- <td class='attr-rw'>
- [R]
- </td>
- <td class='attr-name'>scale</td>
- <td class='attr-desc'><p>Scale of the temperature. Look at <a href="BasicTemperature.html#SCALES">SCALES</a> for possible values.</p></td>
- </tr>
-
- </table>
-
<!-- Methods -->
- <div class="sectiontitle">Class Public methods</div>
-
- <div class="method">
- <div class="title method-title" id="method-c-5B-5D">
-
- <b>[](degrees:, scale:)<br />[](degrees, scale)</b>
-
- <a href="../classes/BasicTemperature.html#method-c-5B-5D" name="method-c-5B-5D" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Creates a new instance of <a href="Temperature.html"><code>Temperature</code></a>. Alias for <code>new</code>.</p>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-c-5B-5D_source')" id="l_method-c-5B-5D_source">show</a>
-
- </p>
- <div id="method-c-5B-5D_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 215</span>
-<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>)
- <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>)
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-c-new">
-
- <b>new(degrees:, scale:)<br />new(degrees, scale)</b>
-
- <a href="../classes/BasicTemperature.html#method-c-new" name="method-c-new" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Creates a new instance of <a href="Temperature.html"><code>Temperature</code></a>. Is aliased as <code>[]</code>.</p>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
-
- </p>
- <div id="method-c-new_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 226</span>
-<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>)
- <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>)
-
- <span class="ruby-keyword">if</span> <span class="ruby-identifier">keyword_arguments</span>.<span class="ruby-identifier">any?</span>
- <span class="ruby-identifier">initialize_via_keywords_arguments</span>(<span class="ruby-identifier">keyword_arguments</span>)
- <span class="ruby-keyword">else</span> <span class="ruby-comment"># positional_arguments.any?</span>
- <span class="ruby-identifier">initialize_via_positional_arguments</span>(<span class="ruby-identifier">positional_arguments</span>)
- <span class="ruby-keyword">end</span>
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
-
- <div class="sectiontitle">Instance Public methods</div>
-
- <div class="method">
- <div class="title method-title" id="method-i-2B">
-
- <b>+(temperature)<br />+(numeric)</b>
-
- <a href="../classes/BasicTemperature.html#method-i-2B" name="method-i-2B" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Performs addition. Returns a new <a href="Temperature.html"><code>Temperature</code></a>.</p>
-
-<pre><code>Temperature[20, :celsius] + Temperature[10, :celsius]
-# => 30 °C
-</code></pre>
-
-<p>If the second temperature has a different scale, the first temperature is automatically converted to that scale before <code>degrees</code> addition.</p>
-
-<pre><code>Temperature[283.15, :kelvin] + Temperature[20, :celsius]
-# => 30 °C
-</code></pre>
-
-<p>Returned temperature will have the same scale as the second temperature.</p>
-
-<p>It is possible to add numerics.</p>
-
-<pre><code>Temperature[20, :celsius] + 10
-# => 30 °C
-</code></pre>
-
-<p>In such cases, returned temperature will have the same scale as the first temperature.</p>
-
-<p>Also <a href="https://ruby-doc.org/core/Numeric.html#method-i-coerce">Ruby coersion mechanism</a> is supported.</p>
-
-<pre><code>10 + Temperature[20, :celsius]
-# => 30 °C
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-2B_source')" id="l_method-i-2B_source">show</a>
-
- </p>
- <div id="method-i-2B_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 493</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">+</span>(<span class="ruby-identifier">other</span>)
- <span class="ruby-identifier">assert_numeric_or_temperature!</span>(<span class="ruby-identifier">other</span>)
-
- <span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span> =
- <span class="ruby-keyword">case</span> <span class="ruby-identifier">other</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">Numeric</span>
- [<span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>]
- <span class="ruby-keyword">when</span> <span class="ruby-constant">BasicTemperature</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">+</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">other</span>.<span class="ruby-identifier">scale</span>]
- <span class="ruby-keyword">end</span>
-
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span>)
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-2D">
-
- <b>-(temperature)<br />-(numeric)</b>
-
- <a href="../classes/BasicTemperature.html#method-i-2D" name="method-i-2D" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Performs subtraction. Returns a new <a href="Temperature.html"><code>Temperature</code></a>.</p>
-
-<pre><code>Temperature[20, :celsius] - Temperature[10, :celsius]
-# => 10 °C
-</code></pre>
-
-<p>If the second temperature has a different scale, the first temperature is automatically converted to that scale before <code>degrees</code> subtraction.</p>
-
-<pre><code>Temperature[283.15, :kelvin] + Temperature[10, :celsius]
-# => 10 °C
-</code></pre>
-
-<p>Returned temperature will have the same scale as the second temperature.</p>
-
-<p>It is possible to subtract numerics.</p>
-
-<pre><code>Temperature[20, :celsius] - 10
-# => 10 °C
-</code></pre>
-
-<p>In such cases, returned temperature will have the same scale as the first temperature.</p>
-
-<p>Also <a href="https://ruby-doc.org/core/Numeric.html#method-i-coerce">Ruby coersion mechanism</a> is supported.</p>
-
-<pre><code>10 - Temperature[20, :celsius]
-# => -10 °C
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-2D_source')" id="l_method-i-2D_source">show</a>
-
- </p>
- <div id="method-i-2D_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 537</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">-</span>(<span class="ruby-identifier">other</span>)
- <span class="ruby-keyword">self</span> <span class="ruby-operator">+</span> <span class="ruby-operator">-</span><span class="ruby-identifier">other</span>
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-2D-40">
-
- <b>-@</b>()
-
- <a href="../classes/BasicTemperature.html#method-i-2D-40" name="method-i-2D-40" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Returns a new <a href="Temperature.html"><code>Temperature</code></a> with negated <code>degrees</code>.</p>
-
-<pre><code>-Temperature[20, :celsius]
-# => -20 °C
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-2D-40_source')" id="l_method-i-2D-40_source">show</a>
-
- </p>
- <div id="method-i-2D-40_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 547</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">-@</span>
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-operator">-</span><span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>)
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-3C-3D-3E">
-
- <b><=></b>(other)
-
- <a href="../classes/BasicTemperature.html#method-i-3C-3D-3E" name="method-i-3C-3D-3E" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Compares temperture with <code>other</code> temperature.</p>
-
-<p>Returns <code>0</code> if they are considered as equal.</p>
-
-<p>Two temperatures are considered as equal when they have the same amount of <code>degrees</code>.</p>
-
-<p>Returns <code>-1</code> if temperature is lower than <code>other</code> temperature.</p>
-
-<p>Returns <code>1</code> if temperature is higher than <code>other</code> temperature.</p>
-
-<p>If <code>other</code> temperature has a different scale, temperature is automatically converted to that scale before <code>degrees</code> comparison.</p>
-
-<pre><code>Temperature[20, :celsius] <=> Temperature[20, :celsius]
-# => 0
-
-Temperature[20, :celsius] <=> Temperature[293.15, :kelvin]
-# => 0
-</code></pre>
-
-<p>IMPORTANT!!!</p>
-
-<p>This method rounds <code>degrees</code> to the nearest value with a precision of 2 decimal digits.</p>
-
-<p>This means the following:</p>
-
-<pre><code>Temperature[20.020, :celsius] <=> Temperature[20.024, :celsius]
-# => 0
-
-Temperature[20.025, :celsius] <=> Temperature[20.029, :celsius]
-# => 0
-
-Temperature[20.024, :celsius] <=> Temperature[20.029, :celsius]
-# => -1
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-3C-3D-3E_source')" id="l_method-i-3C-3D-3E_source">show</a>
-
- </p>
- <div id="method-i-3C-3D-3E_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 457</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title"><=></span>(<span class="ruby-identifier">other</span>)
- <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>)
-
- <span class="ruby-identifier">compare_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-identifier">other</span>.<span class="ruby-identifier">degrees</span>)
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-set_degrees">
-
- <b>set_degrees</b>(degrees)
-
- <a href="../classes/BasicTemperature.html#method-i-set_degrees" name="method-i-set_degrees" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Returns a new <a href="Temperature.html"><code>Temperature</code></a> with updated <code>degrees</code>.</p>
-
-<pre><code>temperature = Temperature[0, :celsius]
-# => 0 °C
-
-new_temperature = temperature.set_degrees(15)
-# => 15 °C
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-set_degrees_source')" id="l_method-i-set_degrees_source">show</a>
-
- </p>
- <div id="method-i-set_degrees_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 246</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_degrees</span>(<span class="ruby-identifier">degrees</span>)
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span>)
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-set_scale">
-
- <b>set_scale</b>(scale)
-
- <a href="../classes/BasicTemperature.html#method-i-set_scale" name="method-i-set_scale" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Returns a new <a href="Temperature.html"><code>Temperature</code></a> with updated <code>scale</code>.</p>
-
-<pre><code>temperature = Temperature[0, :celsius]
-# => 0 °C
-
-new_temperature = temperature.set_scale(:kelvin)
-# => 0 K
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-set_scale_source')" id="l_method-i-set_scale_source">show</a>
-
- </p>
- <div id="method-i-set_scale_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 261</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_scale</span>(<span class="ruby-identifier">scale</span>)
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span>)
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-to_celsius">
-
- <b>to_celsius</b>()
-
- <a href="../classes/BasicTemperature.html#method-i-to_celsius" name="method-i-to_celsius" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Converts temperature to Celsius scale. If temperature is already in Celsius, returns current temperature object.</p>
-
-<p>Memoizes subsequent calls.</p>
-
-<p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
-<ol><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-fahrenheit.html">Celsius to Fahrenheit</a>.</p>
-</li><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-kelvin.html">Celsius to Kelvin</a>.</p>
-</li><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-rankine.html">Celsius to Rankine</a>.</p>
-</li></ol>
-
-<pre><code>Temperature[0, :fahrenheit].to_celsius
-# => -17.78 °C
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-to_celsius_source')" id="l_method-i-to_celsius_source">show</a>
-
- </p>
- <div id="method-i-to_celsius_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 308</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_celsius</span>
- <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">-></span> {
- <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>
-
- <span class="ruby-identifier">degrees</span> =
- <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
- (<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>)
- <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
- <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-keyword">when</span> <span class="ruby-constant">RANKINE</span>
- (<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>)
- <span class="ruby-keyword">end</span>
-
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">CELSIUS</span>)
- })
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-to_fahrenheit">
-
- <b>to_fahrenheit</b>()
-
- <a href="../classes/BasicTemperature.html#method-i-to_fahrenheit" name="method-i-to_fahrenheit" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Converts temperature to Fahrenheit scale. If temperature is already in Fahrenheit, returns current temperature object.</p>
-
-<p>Memoizes subsequent calls.</p>
-
-<p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
-<ol><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-celsius.html">Fahrenheit to Celsius</a>.</p>
-</li><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-kelvin.html">Fahrenheit to Kelvin</a>.</p>
-</li><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-rankine.html">Fahrenheit to Rankine</a>.</p>
-</li></ol>
-
-<pre><code>Temperature[0, :celsius].to_fahrenheit
-# => 32 °F
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-to_fahrenheit_source')" id="l_method-i-to_fahrenheit_source">show</a>
-
- </p>
- <div id="method-i-to_fahrenheit_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 340</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_fahrenheit</span>
- <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">-></span> {
- <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>
-
- <span class="ruby-identifier">degrees</span> =
- <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
- <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>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
- <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>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
- <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-keyword">end</span>
-
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">FAHRENHEIT</span>)
- })
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-to_kelvin">
-
- <b>to_kelvin</b>()
-
- <a href="../classes/BasicTemperature.html#method-i-to_kelvin" name="method-i-to_kelvin" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Converts temperature to Kelvin scale. If temperature is already in Kelvin, returns current</p>
-
-<pre><code>temperature object.
-</code></pre>
-
-<p>Memoizes subsequent calls.</p>
-
-<p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
-<ol><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-celsius.html">Kelvin to Celsius</a>.</p>
-</li><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-fahrenheit.html">Kelvin to Fahrenheit</a>.</p>
-</li><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-rankine.html">Kelvin to Rankine</a>.</p>
-</li></ol>
-
-<pre><code>Temperature[0, :kelvin].to_rankine
-# => 0 °R
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-to_kelvin_source')" id="l_method-i-to_kelvin_source">show</a>
-
- </p>
- <div id="method-i-to_kelvin_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 372</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_kelvin</span>
- <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">-></span> {
- <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>
-
- <span class="ruby-identifier">degrees</span> =
- <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
- <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-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
- (<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>)
- <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
- <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>)
- <span class="ruby-keyword">end</span>
-
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">KELVIN</span>)
- })
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-to_rankine">
-
- <b>to_rankine</b>()
-
- <a href="../classes/BasicTemperature.html#method-i-to_rankine" name="method-i-to_rankine" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Converts temperature to Rankine scale. If temperature is already in Rankine, returns current temperature object.</p>
-
-<p>Memoizes subsequent calls.</p>
-
-<p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
-<ol><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-celsius.html">Rankine to Celsius</a>.</p>
-</li><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-fahrenheit.html">Rankine to Fahrenheit</a>.</p>
-</li><li>
-<p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-kelvin.html">Rankine to Kelvin</a>.</p>
-</li></ol>
-
-<pre><code>Temperature[0, :rankine].to_kelvin
-# => 0 K
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-to_rankine_source')" id="l_method-i-to_rankine_source">show</a>
-
- </p>
- <div id="method-i-to_rankine_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 404</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_rankine</span>
- <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">-></span> {
- <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>
-
- <span class="ruby-identifier">degrees</span> =
- <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
- (<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>)
- <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
- <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-keyword">when</span> <span class="ruby-constant">KELVIN</span>
- <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-keyword">end</span>
-
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">RANKINE</span>)
- })
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
- <div class="method">
- <div class="title method-title" id="method-i-to_scale">
-
- <b>to_scale</b>(scale)
-
- <a href="../classes/BasicTemperature.html#method-i-to_scale" name="method-i-to_scale" class="permalink">Link</a>
- </div>
-
-
- <div class="description">
- <p>Converts temperature to specific <code>scale</code>. If temperature is already in desired <code>scale</code>, returns current temperature object.</p>
-
-<p>Raises <a href="BasicTemperature/InvalidScaleError.html">InvalidScaleError</a> when <code>scale</code> can not be casted to any possible scale value (see <a href="BasicTemperature.html#SCALES">SCALES</a>).</p>
-
-<pre><code>Temperature[60, :fahrenheit].to_scale(:celsius)
-# => 15.56 °C
-</code></pre>
- </div>
-
-
-
-
-
-
-
-
- <div class="sourcecode">
-
- <p class="source-link">
- Source:
- <a href="javascript:toggleSource('method-i-to_scale_source')" id="l_method-i-to_scale_source">show</a>
-
- </p>
- <div id="method-i-to_scale_source" class="dyn-source">
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 277</span>
-<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_scale</span>(<span class="ruby-identifier">scale</span>)
- <span class="ruby-identifier">casted_scale</span> = <span class="ruby-identifier">cast_scale</span>(<span class="ruby-identifier">scale</span>)
-
- <span class="ruby-identifier">assert_valid_scale!</span>(<span class="ruby-identifier">casted_scale</span>)
-
- <span class="ruby-keyword">case</span> <span class="ruby-identifier">casted_scale</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
- <span class="ruby-identifier">to_celsius</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
- <span class="ruby-identifier">to_fahrenheit</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
- <span class="ruby-identifier">to_kelvin</span>
- <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
- <span class="ruby-identifier">to_rankine</span>
- <span class="ruby-keyword">end</span>
-<span class="ruby-keyword">end</span></pre>
- </div>
- </div>
-
- </div>
-
-
</div>
</div>