basic_temperature 0.2.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/.inch.yml +3 -0
  3. data/.rubocop.yml +3 -0
  4. data/CHANGELOG.md +68 -7
  5. data/README.md +41 -61
  6. data/bin/console +1 -1
  7. data/docs/classes/BasicTemperature.html +27 -1129
  8. data/docs/classes/BasicTemperature/Temperature.html +1239 -0
  9. data/docs/classes/BasicTemperature/Temperature/AdditionalHelpers.html +78 -0
  10. data/docs/classes/BasicTemperature/Temperature/Assertions.html +78 -0
  11. data/docs/classes/BasicTemperature/Temperature/Casting.html +78 -0
  12. data/docs/classes/BasicTemperature/Temperature/Errors.html +109 -0
  13. data/docs/classes/BasicTemperature/Temperature/Errors/InitializationArguments.html +94 -0
  14. data/docs/classes/BasicTemperature/Temperature/Errors/InvalidDegrees.html +94 -0
  15. data/docs/classes/BasicTemperature/Temperature/Errors/InvalidNumeric.html +94 -0
  16. data/docs/classes/BasicTemperature/Temperature/Errors/InvalidNumericOrTemperature.html +94 -0
  17. data/docs/classes/BasicTemperature/Temperature/Errors/InvalidScale.html +94 -0
  18. data/docs/classes/BasicTemperature/Temperature/Initialization.html +78 -0
  19. data/docs/classes/BasicTemperature/Temperature/Memoization.html +78 -0
  20. data/docs/classes/BasicTemperature/Temperature/Rounding.html +78 -0
  21. data/docs/classes/Object.html +3 -175
  22. data/docs/created.rid +12 -4
  23. data/docs/files/lib/basic_temperature/alias_rb.html +73 -0
  24. data/docs/files/lib/basic_temperature/temperature/additional_helpers_rb.html +94 -0
  25. data/docs/files/lib/basic_temperature/temperature/assertions_rb.html +94 -0
  26. data/docs/files/lib/basic_temperature/temperature/casting_rb.html +94 -0
  27. data/docs/files/lib/basic_temperature/temperature/errors_rb.html +119 -0
  28. data/docs/files/lib/basic_temperature/temperature/initialization_rb.html +94 -0
  29. data/docs/files/lib/basic_temperature/temperature/memoization_rb.html +94 -0
  30. data/docs/files/lib/basic_temperature/temperature/rounding_rb.html +94 -0
  31. data/docs/files/lib/basic_temperature/temperature_rb.html +17 -1
  32. data/docs/files/lib/basic_temperature/version_rb.html +2 -2
  33. data/docs/files/lib/basic_temperature_rb.html +2 -30
  34. data/docs/js/navigation.js.gz +0 -0
  35. data/docs/js/search_index.js +1 -1
  36. data/docs/js/search_index.js.gz +0 -0
  37. data/docs/js/searcher.js.gz +0 -0
  38. data/docs/panel/links.html +16 -0
  39. data/docs/panel/tree.js +1 -1
  40. data/lib/basic_temperature.rb +3 -700
  41. data/lib/basic_temperature/alias.rb +5 -0
  42. data/lib/basic_temperature/temperature.rb +515 -2
  43. data/lib/basic_temperature/temperature/additional_helpers.rb +17 -0
  44. data/lib/basic_temperature/temperature/assertions.rb +30 -0
  45. data/lib/basic_temperature/temperature/casting.rb +19 -0
  46. data/lib/basic_temperature/temperature/errors.rb +50 -0
  47. data/lib/basic_temperature/temperature/initialization.rb +32 -0
  48. data/lib/basic_temperature/temperature/memoization.rb +26 -0
  49. data/lib/basic_temperature/temperature/rounding.rb +13 -0
  50. data/lib/basic_temperature/version.rb +2 -2
  51. metadata +32 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 306e98f11732ad722fb25ecf4cbdfbe8b0c1151e34ddffa2fa202656fd16d2de
4
- data.tar.gz: 1f287528c4653c3f270ad8ec6d27afd2ee7e097b9b1b9a4dc216daefb9b7caa4
3
+ metadata.gz: cc03cf17fb7c5079a7da172ebf3a4dc77294c53ee66618fc1228eced28812275
4
+ data.tar.gz: f03832fb7a61697a504d2186330e9ac7cf18805d1ec404ab3bef08a704fc0979
5
5
  SHA512:
6
- metadata.gz: 07a9da936a9b9e282423b91993f09255ddd8783412477d77d412401b6f7b110cada000a95dea742725a0584ab3852f3760691d6dc714a528af5a51a3224290ea
7
- data.tar.gz: 25833d006ce3d8d000ecd0ee30ebe80e66acbbbe4f9c2fecbea6fb44732057e240a6cddd44fa2acf23f7b32c313b0a0f95a0a660c0f7b2a37fe20cd1c37f7ade
6
+ metadata.gz: 126398fb6aa8d8f9a6abbd2292b1ebeb9860acf228e44cc5bbcbd9aa322b8c147227b3b53f88233bd9d22802d7c1a9e2be7df777afb555dea26336802b614c38
7
+ data.tar.gz: 4b16e8c95746d1fd5d812bd2661cbbffdf3fe520ae148861a8f21233fd9fd3b8c8aca4c019a3e1daa25065dd2832508f758f0464971e0efa1eefd185bedc47d1
data/.inch.yml ADDED
@@ -0,0 +1,3 @@
1
+ files:
2
+ included:
3
+ - lib/**/*.rb
data/.rubocop.yml CHANGED
@@ -18,6 +18,9 @@ Metrics/MethodLength:
18
18
  Style/AsciiComments:
19
19
  Enabled: No
20
20
 
21
+ Style/Documentation:
22
+ Severity: warning
23
+
21
24
  Style/Lambda:
22
25
  EnforcedStyle: literal
23
26
 
data/CHANGELOG.md CHANGED
@@ -1,15 +1,76 @@
1
+ ## 1.0.0
2
+ ### Features:
3
+ - `Temperature#boil_water?`, `Temperature#freeze_water?` (#47).
4
+
5
+ ### Removals
6
+ - `BasicTemperature#==`, since it is generated by `Comparable` (#43).
7
+ - Remove Math, since it provides more confusion than benefit (#51).
8
+
9
+ ### Docs
10
+ - Added link to docs in README.md (#42).
11
+
12
+ ### Tech improvements:
13
+ - Global refactoring: splitting ot the God Object into modules (#43) .
14
+ - [Inch CI](https://inch-ci.org/) setup (#45).
15
+
16
+ ## 0.2.2
17
+ ### Features:
18
+ - Include Comparable (#24).
19
+ - Introduction of shorter form (`Temperature` instead of `BasicTemperature::Temperature`) (#25).
20
+ - Added simple memoization (#26).
21
+ - Added rounding (#26).
22
+ - Alias `[]` for `new` (#27).
23
+ - Added support of `Rankine` scale.
24
+ - `Temperature#inspect`.
25
+
26
+ ### Fixes:
27
+ - Updated `BasicTemperature#==`.
28
+ (When two temperatures had different scales - automatic conversion was not performed.) (#18).
29
+ - Recticted Rubocop version for Code Climate (#22).
30
+ - Typo `Celsium` instead of `Celcius` (#23).
31
+ - Added Gemfile.lock to .gitignore (#38).
32
+
33
+ ### Docs
34
+ - Added `Active Development Warning` (#19).
35
+ - Badges: Gem Version, Build Status, Maintainability, Coverage Status, License: MIT, Patreon, Inch CI (#14) (#20) (#40).
36
+ - Added docs for all public API (#38).
37
+ - Added usage section in README.md (#38).
38
+
39
+ ### Tech improvements:
40
+ - [Coverals](https://docs.coveralls.io/ruby-on-rails) setup (#10).
41
+ - [SimpleCov](https://github.com/colszowka/simplecov) setup (#10).
42
+ - [Code Climate](https://codeclimate.com/) setup (#13).
43
+ - [ReverseCoverage] setup (#21).
44
+ - [SDoc] setup (#38).
45
+ - [Rerun] setup (#38).
46
+ - Autodeploy of docs to Github Pages (#39).
47
+
48
+
1
49
  ## 0.2.1
2
50
  ### Features:
3
- - Spaceship operator <=>
51
+ - Spaceship operator <=> (#2).
4
52
 
5
53
  ### Tech improvements:
6
- - [byebug](https://github.com/deivid-rodriguez/byebug) as dev dependency
7
- - [rspec](https://rspec.info/) as dev dependency
8
- - [rubocop](https://github.com/rubocop-hq/rubocop) as dev dependency
9
- - [Travis CI](https://travis-ci.com/) setup
54
+ - [Byebug](https://github.com/deivid-rodriguez/byebug) setup (#1).
55
+ - [RSpec](https://rspec.info/) setup (#3).
56
+ - [RuboCop](https://github.com/rubocop-hq/rubocop) setup (#5).
57
+ - [Travis CI](https://travis-ci.com/) setup (#4).
58
+
10
59
 
11
60
  ## 0.2.0
12
- - 'Accidentally' yanked
61
+ - 'Accidentally' yanked.
62
+
13
63
 
14
64
  ## 0.1.0
15
- - Initial Release.
65
+ - Initial Release.
66
+
67
+ ### Features:
68
+ - Creation of `Temperature` using positional arguments.
69
+ - Creation of `Temperature` using keyword arguments.
70
+ - Creation of `Temperature`s from already existing temperature objects (`Temperature#set_degrees`, `Temperature#set_scale`).
71
+ - Conversion to Celsius, Fahrenheit, Kelvin.
72
+ - Dynamic conversion (`Temperature#to_scale`).
73
+ - Equality operator `==`.
74
+ - Addition of `Temperature`s.
75
+ - Subtraction of `Temperature`s.
76
+ - Support of Ruby coersion mechanism.
data/README.md CHANGED
@@ -1,23 +1,27 @@
1
- ## Basic Temperature ##
1
+ <h1 align="center">
2
+ Basic Temperature
3
+ </h1>
2
4
 
3
5
  [![Gem Version](https://badge.fury.io/rb/basic_temperature.svg)](https://rubygems.org/gems/basic_temperature) [![Build Status](https://travis-ci.com/marian13/basic_temperature.svg?branch=master)](https://travis-ci.com/marian13/basic_temperature) [![Maintainability](https://api.codeclimate.com/v1/badges/21dc5d50cf5de8346a3c/maintainability)](https://codeclimate.com/github/marian13/basic_temperature/maintainability) [![Coverage Status](https://coveralls.io/repos/github/marian13/basic_temperature/badge.svg)](https://coveralls.io/github/marian13/basic_temperature) [![Inline docs](http://inch-ci.org/github/marian13/basic_temperature.svg?branch=master)](http://inch-ci.org/github/marian13/basic_temperature)
4
6
  [![Patreon](https://img.shields.io/badge/patreon-donate-orange.svg)](https://www.patreon.com/user?u=31435716&fan_landing=true)
5
7
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
8
 
7
- ![alt text](https://raw.githubusercontent.com/marian13/basic_temperature/master/logo.png)
9
+ <p align="center">
10
+ <img src="https://raw.githubusercontent.com/marian13/basic_temperature/master/logo.png">
11
+ </p>
8
12
 
9
13
  `basic_temperature` is a Ruby library which provides a simple [value object](https://martinfowler.com/bliki/ValueObject.html) to work with temperatures and
10
14
  allows to perform basic operations like conversion from Celsius to Kelvin, from Kelvin to Fahrenheit etc.
11
15
 
12
16
 
13
17
  ### Features
14
- - Provides a `BasicTemperature` class which encapsulates all information about a certain temperature, such
18
+ - Provides a `Temperature` class which encapsulates all information about a certain temperature, such
15
19
  as its amount of degrees and its scale.
16
20
  - Provides APIs for exchanging temperatures from one scale to another (currently Celsius, Fahrenheit, Kelvin and
17
21
  Rankine).
18
22
 
19
23
  - Allows comparing temperatures between each other.
20
- - Supports basic math operations like addition and subtraction.
24
+ - Queries like `boil_water?`, `freeze_water?`.
21
25
  - Tested against Ruby 2.3, 2.4, 2.5, 2.6 & 2.7. See
22
26
  [.travis-ci.yml](https://github.com/marian13/basic_temperature/blob/9b13cb9909b57c51bb5dc05a8989d07a314e67d6/.travis.yml)
23
27
  for the exact versions.
@@ -26,29 +30,39 @@ for the exact versions.
26
30
 
27
31
  * None.
28
32
 
33
+ ### Documentation
34
+
35
+ * Visit https://marian13.github.io/basic_temperature/ to view the documentation.
36
+
29
37
  ## Installation
30
38
 
31
- Add this line to your application's Gemfile:
39
+ Gemfile:
32
40
 
33
41
  ```ruby
34
- gem 'basic_temperature'
42
+ gem 'basic_temperature', '~> 1.0.0'
35
43
  ```
36
44
 
37
- #### Warning
45
+ And then run:
46
+
47
+ $ bundle install
48
+
49
+ And that's it.
38
50
 
39
- Since this gem is under active development and there are often backward-incompatible changes between minor releases, you might want to use a conservative version lock in your Gemfile:
51
+ You can access all the features of `basic_temperature` by creating instances of `BasicTemperature::Temperature`.
52
+
53
+ But there is a shorter form.
54
+
55
+ If `Temperature` constant was not used before in your app, you can add this line to your Gemfile:
40
56
 
41
57
  ```ruby
42
- gem 'basic_temperature', '~> 0.2.1'
58
+ gem 'basic_temperature', '~> 1.0.0', require: ['basic_temperature/alias']
43
59
  ```
44
60
 
45
- And then execute:
61
+ This way `BasicTemperature::Temperature` class will be accesible simply by `Temperature`.
46
62
 
47
- $ bundle install
63
+ The following guide assumes you have chosen the shorter form.
48
64
 
49
- Or install it yourself as:
50
-
51
- $ gem install basic_temperature
65
+ If not, just replace all `Temperature` to `BasicTemperature::Temperature`.
52
66
 
53
67
  ## Usage
54
68
 
@@ -189,55 +203,13 @@ Temperature[20.024, :celsius] == Temperature[20.029, :celsius]
189
203
  # => false
190
204
  ```
191
205
 
192
- ### Math
193
-
194
- #### Addition/Subtraction.
195
-
206
+ ### Queries
196
207
  ```ruby
197
- Temperature[20, :celsius] + Temperature[10, :celsius]
198
- # => 30 °C
199
-
200
- Temperature[20, :celsius] - Temperature[10, :celsius]
201
- # => 10 °C
202
- ```
203
-
204
- If second temperature has a different scale, first temperature is automatically converted to that scale
205
- before `degrees` addition/subtraction.
206
-
207
- ```ruby
208
- Temperature[283.15, :kelvin] + Temperature[10, :celsius]
209
- # => 10 °C
210
- ```
211
-
212
- Returned temperature will have the same scale as the second temperature.
213
-
214
- It is possible to add/subtract numerics.
215
-
216
- ```ruby
217
- Temperature[20, :celsius] + 10
218
- # => 30 °C
219
-
220
- Temperature[20, :celsius] - 10
221
- # => 10 °C
222
- ```
223
-
224
- In such cases, returned temperature will have the same scale as the first temperature.
225
-
226
- Also [Ruby coersion mechanism](https://ruby-doc.org/core/Numeric.html#method-i-coerce) is supported.
227
-
228
- ```ruby
229
- 10 + Temperature[20, :celsius]
230
- # => 30 °C
231
-
232
- 10 - Temperature[20, :celsius]
233
- # => -10 °C
234
- ```
235
-
236
- #### Negation
208
+ Temperature[0, :celsius].boil_water?
209
+ # => false
237
210
 
238
- ```ruby
239
- -Temperature[20, :celsius]
240
- # => -20 °C
211
+ Temperature[0, :celsius].freeze_water?
212
+ # => true
241
213
  ```
242
214
 
243
215
  ## Versioning
@@ -247,6 +219,14 @@ Basic Temperature follows the [Semantic Versioning](https://semver.org/) standar
247
219
 
248
220
  Bug reports and pull requests are welcome on GitHub at https://github.com/marian13/basic_temperature.
249
221
 
222
+ ## Development
223
+
224
+ * Check specs: `bundle exec rspec`.
225
+
226
+ * Check linter: `bundle exec rubocop`.
227
+
228
+ * Update docs: `bundle exec sdoc lib -T rails -o docs`.
229
+
250
230
  ## License
251
231
 
252
232
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/bin/console CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'bundler/setup'
4
- require 'basic_temperature/temperature'
4
+ require 'basic_temperature/alias'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -14,35 +14,39 @@
14
14
  <meta property="og:title" value="BasicTemperature">
15
15
 
16
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
17
 
22
18
  <meta name="keywords" content="BasicTemperature class">
23
19
 
24
- <meta name="keywords" content="[], new, set_degrees, set_scale, to_scale, to_celsius, to_fahrenheit, to_kelvin, to_rankine, <=>, +, -, -@">
25
-
26
20
  </head>
27
21
 
28
22
  <body>
29
23
  <div class="banner">
30
24
 
31
25
  <h1>
32
- <span class="type">Class</span>
26
+ <span class="type">Module</span>
33
27
  BasicTemperature
34
28
 
35
- <span class="parent">&lt;
36
-
37
- <a href="Object.html">Object</a>
38
-
39
- </span>
40
-
41
29
  </h1>
42
30
  <ul class="files">
43
31
 
44
32
  <li><a href="../files/lib/basic_temperature_rb.html">lib/basic_temperature.rb</a></li>
45
33
 
34
+ <li><a href="../files/lib/basic_temperature/temperature_rb.html">lib/basic_temperature/temperature.rb</a></li>
35
+
36
+ <li><a href="../files/lib/basic_temperature/temperature/additional_helpers_rb.html">lib/basic_temperature/temperature/additional_helpers.rb</a></li>
37
+
38
+ <li><a href="../files/lib/basic_temperature/temperature/assertions_rb.html">lib/basic_temperature/temperature/assertions.rb</a></li>
39
+
40
+ <li><a href="../files/lib/basic_temperature/temperature/casting_rb.html">lib/basic_temperature/temperature/casting.rb</a></li>
41
+
42
+ <li><a href="../files/lib/basic_temperature/temperature/errors_rb.html">lib/basic_temperature/temperature/errors.rb</a></li>
43
+
44
+ <li><a href="../files/lib/basic_temperature/temperature/initialization_rb.html">lib/basic_temperature/temperature/initialization.rb</a></li>
45
+
46
+ <li><a href="../files/lib/basic_temperature/temperature/memoization_rb.html">lib/basic_temperature/temperature/memoization.rb</a></li>
47
+
48
+ <li><a href="../files/lib/basic_temperature/temperature/rounding_rb.html">lib/basic_temperature/temperature/rounding.rb</a></li>
49
+
46
50
  <li><a href="../files/lib/basic_temperature/version_rb.html">lib/basic_temperature/version.rb</a></li>
47
51
 
48
52
  </ul>
@@ -50,184 +54,6 @@
50
54
  <div id="bodyContent">
51
55
  <div id="content">
52
56
 
53
- <div class="description">
54
-
55
- <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>
56
-
57
- <p>Supported scales: <code>Celsius</code>, <code>Fahrenheit</code>, <code>Kelvin</code> and <code>Rankine</code>.</p>
58
-
59
- <h2 id="class-BasicTemperature-label-Creating+Temperatures">Creating Temperatures</h2>
60
-
61
- <p>A new temperature can be created in multiple ways:</p>
62
- <ul><li>
63
- <p>Using keyword arguments:</p>
64
-
65
- <pre><code>Temperature.new(degrees: 0, scale: :celsius)
66
- </code></pre>
67
- </li><li>
68
- <p>Using positional arguments:</p>
69
-
70
- <pre><code>Temperature.new(0, :celsius)
71
- </code></pre>
72
- </li><li>
73
- <p>Even more concise way using <code>Temperature.[]</code> (an alias of <code>Temperature.new</code>):</p>
74
-
75
- <pre><code>Temperature[0, :celsius]
76
- </code></pre>
77
- </li></ul>
78
-
79
- <h2 id="class-BasicTemperature-label-Creating+Temperatures+from+already+existing+temperature+objects">Creating Temperatures from already existing temperature objects</h2>
80
-
81
- <p>Sometimes it is useful to create a new temperature from already existing one.</p>
82
-
83
- <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>
84
-
85
- <p>Since temperatures are <a href="https://martinfowler.com/bliki/ValueObject.html">Value Objects</a>, both methods returns new instances.</p>
86
-
87
- <p>Examples:</p>
88
-
89
- <pre><code>temperature = Temperature[0, :celsius]
90
- # =&gt; 0 °C
91
-
92
- new_temperature = temperature.set_degrees(15)
93
- # =&gt; 15 °C
94
-
95
- temperature = Temperature[0, :celsius]
96
- # =&gt; 0 °C
97
-
98
- new_temperature = temperature.set_scale(:kelvin)
99
- # =&gt; 0 K
100
- </code></pre>
101
-
102
- <h2 id="class-BasicTemperature-label-Conversions">Conversions</h2>
103
-
104
- <p>Temperatures can be converted to diffirent scales.</p>
105
-
106
- <p>Currently, the following scales are supported: <code>Celsius</code>, <code>Fahrenheit</code>, <code>Kelvin</code> and <code>Rankine</code>.</p>
107
-
108
- <pre><code>Temperature[20, :celsius].to_celsius
109
- # =&gt; 20 °C
110
-
111
- Temperature[20, :celsius].to_fahrenheit
112
- # =&gt; 68 °F
113
-
114
- Temperature[20, :celsius].to_kelvin
115
- # =&gt; 293.15 K
116
-
117
- Temperature[20, :celsius].to_rankine
118
- # =&gt; 527.67 °R
119
- </code></pre>
120
-
121
- <p>If it is necessary to convert scale dynamically, <a href="BasicTemperature.html#method-i-to_scale">to_scale</a> method is available.</p>
122
-
123
- <pre><code>Temperature[20, :celsius].to_scale(scale)
124
- </code></pre>
125
-
126
- <p>All conversion formulas are taken from <a href="https://www.rapidtables.com/convert/temperature/index.html">RapidTables</a>.</p>
127
-
128
- <p>Conversion precision: 2 accurate digits after the decimal dot.</p>
129
-
130
- <h2 id="class-BasicTemperature-label-Comparison">Comparison</h2>
131
-
132
- <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>
133
-
134
- <p>As a result, all methods from Comparable are available, e.g:</p>
135
-
136
- <pre><code>Temperature[20, :celsius] &lt; Temperature[25, :celsius]
137
- # =&gt; true
138
-
139
- Temperature[20, :celsius] &lt;= Temperature[25, :celsius]
140
- # =&gt; true
141
-
142
- Temperature[20, :celsius] == Temperature[25, :celsius]
143
- # =&gt; false
144
-
145
- Temperature[20, :celsius] &gt; Temperature[25, :celsius]
146
- # =&gt; false
147
-
148
- Temperature[20, :celsius] &gt;= Temperature[25, :celsius]
149
- # =&gt; false
150
-
151
- Temperature[20, :celsius].between?(Temperature[15, :celsius], Temperature[25, :celsius])
152
- # =&gt; true
153
-
154
- # Starting from Ruby 2.4.6
155
- Temperature[20, :celsius].clamp(Temperature[20, :celsius], Temperature[25, :celsius])
156
- # =&gt; 20 °C
157
- </code></pre>
158
-
159
- <p>Please note, if <code>other</code> temperature has a different scale, temperature is automatically converted to that scale before comparison.</p>
160
-
161
- <pre><code>Temperature[20, :celsius] == Temperature[293.15, :kelvin]
162
- # =&gt; true
163
- </code></pre>
164
-
165
- <p>IMPORTANT !!!</p>
166
-
167
- <p><code>degrees</code> are rounded to the nearest value with a precision of 2 decimal digits before comparison.</p>
168
-
169
- <p>This means the following temperatures are considered as equal:</p>
170
-
171
- <pre><code>Temperature[20.020, :celsius] == Temperature[20.024, :celsius]
172
- # =&gt; true
173
-
174
- Temperature[20.025, :celsius] == Temperature[20.029, :celsius]
175
- # =&gt; true
176
- </code></pre>
177
-
178
- <p>while these ones are treated as NOT equal:</p>
179
-
180
- <pre><code>Temperature[20.024, :celsius] == Temperature[20.029, :celsius]
181
- # =&gt; false
182
- </code></pre>
183
-
184
- <h2 id="class-BasicTemperature-label-Math">Math</h2>
185
-
186
- <h4 id="class-BasicTemperature-label-Addition-2FSubtraction.">Addition/Subtraction.</h4>
187
-
188
- <pre><code>Temperature[20, :celsius] + Temperature[10, :celsius]
189
- # =&gt; 30 °C
190
-
191
- Temperature[20, :celsius] - Temperature[10, :celsius]
192
- # =&gt; 10 °C
193
- </code></pre>
194
-
195
- <p>If second temperature has a different scale, first temperature is automatically converted to that scale before <code>degrees</code> addition/subtraction.</p>
196
-
197
- <pre><code>Temperature[283.15, :kelvin] + Temperature[10, :celsius]
198
- # =&gt; 10 °C
199
- </code></pre>
200
-
201
- <p>Returned temperature will have the same scale as the second temperature.</p>
202
-
203
- <p>It is possible to add/subtract numerics.</p>
204
-
205
- <pre><code>Temperature[20, :celsius] + 10
206
- # =&gt; 30 °C
207
-
208
- Temperature[20, :celsius] - 10
209
- # =&gt; 10 °C
210
- </code></pre>
211
-
212
- <p>In such cases, returned temperature will have the same scale as the first temperature.</p>
213
-
214
- <p>Also <a href="https://ruby-doc.org/core/Numeric.html#method-i-coerce">Ruby coersion mechanism</a> is supported.</p>
215
-
216
- <pre><code>10 + Temperature[20, :celsius]
217
- # =&gt; 30 °C
218
-
219
- 10 - Temperature[20, :celsius]
220
- # =&gt; -10 °C
221
- </code></pre>
222
-
223
- <h4 id="class-BasicTemperature-label-Negation">Negation</h4>
224
-
225
- <pre><code>-Temperature[20, :celsius]
226
- # =&gt; -20 °C
227
- </code></pre>
228
-
229
- </div>
230
-
231
57
 
232
58
 
233
59
 
@@ -238,124 +64,24 @@ Temperature[20, :celsius] - 10
238
64
 
239
65
 
240
66
 
241
-
242
-
243
-
244
- <!-- Method ref -->
245
- <div class="sectiontitle">Methods</div>
246
- <dl class="methods">
247
-
248
- <dt>#</dt>
249
- <dd>
250
- <ul>
251
-
252
-
253
- <li>
254
- <a href="#method-i-2B">+</a>,
255
- </li>
256
-
257
-
258
- <li>
259
- <a href="#method-i-2D">-</a>,
260
- </li>
261
-
262
-
263
- <li>
264
- <a href="#method-i-2D-40">-@</a>,
265
- </li>
266
-
267
-
268
- <li>
269
- <a href="#method-i-3C-3D-3E">&lt;=&gt;</a>,
270
- </li>
271
-
272
-
273
- <li>
274
- <a href="#method-c-5B-5D">[]</a>
275
- </li>
276
-
277
- </ul>
278
- </dd>
279
-
280
- <dt>N</dt>
281
- <dd>
282
- <ul>
283
-
284
-
285
- <li>
286
- <a href="#method-c-new">new</a>
287
- </li>
288
-
289
- </ul>
290
- </dd>
291
-
292
- <dt>S</dt>
293
- <dd>
294
- <ul>
295
-
296
-
297
- <li>
298
- <a href="#method-i-set_degrees">set_degrees</a>,
299
- </li>
300
-
301
-
302
- <li>
303
- <a href="#method-i-set_scale">set_scale</a>
304
- </li>
305
-
306
- </ul>
307
- </dd>
308
-
309
- <dt>T</dt>
310
- <dd>
311
- <ul>
312
-
313
-
314
- <li>
315
- <a href="#method-i-to_celsius">to_celsius</a>,
316
- </li>
317
-
318
-
319
- <li>
320
- <a href="#method-i-to_fahrenheit">to_fahrenheit</a>,
321
- </li>
322
-
323
-
324
- <li>
325
- <a href="#method-i-to_kelvin">to_kelvin</a>,
326
- </li>
327
-
328
-
329
- <li>
330
- <a href="#method-i-to_rankine">to_rankine</a>,
331
- </li>
332
-
333
-
334
- <li>
335
- <a href="#method-i-to_scale">to_scale</a>
336
- </li>
337
-
338
- </ul>
339
- </dd>
340
-
341
- </dl>
342
-
343
-
344
-
345
- <!-- Includes -->
346
- <div class="sectiontitle">Included Modules</div>
67
+ <!-- Namespace -->
68
+ <div class="sectiontitle">Namespace</div>
347
69
  <ul>
348
70
 
349
71
  <li>
350
-
351
- Comparable
352
-
72
+ <span class="type">CLASS</span>
73
+ <a href="BasicTemperature/Temperature.html">BasicTemperature::Temperature</a>
353
74
  </li>
354
75
 
355
76
  </ul>
356
77
 
357
78
 
358
79
 
80
+
81
+
82
+
83
+
84
+
359
85
 
360
86
 
361
87
 
@@ -368,70 +94,10 @@ Temperature[20, :celsius] - 10
368
94
  <div class="sectiontitle">Constants</div>
369
95
  <table border='0' cellpadding='5'>
370
96
 
371
- <tr valign='top'>
372
- <td class="attr-name">CELSIUS</td>
373
- <td>=</td>
374
- <td class="attr-value">&#39;celsius&#39;</td>
375
- </tr>
376
-
377
- <tr valign='top'>
378
- <td>&nbsp;</td>
379
- <td colspan="2" class="attr-desc"></td>
380
- </tr>
381
-
382
-
383
- <tr valign='top'>
384
- <td class="attr-name">FAHRENHEIT</td>
385
- <td>=</td>
386
- <td class="attr-value">&#39;fahrenheit&#39;</td>
387
- </tr>
388
-
389
- <tr valign='top'>
390
- <td>&nbsp;</td>
391
- <td colspan="2" class="attr-desc"></td>
392
- </tr>
393
-
394
-
395
- <tr valign='top'>
396
- <td class="attr-name">KELVIN</td>
397
- <td>=</td>
398
- <td class="attr-value">&#39;kelvin&#39;</td>
399
- </tr>
400
-
401
- <tr valign='top'>
402
- <td>&nbsp;</td>
403
- <td colspan="2" class="attr-desc"></td>
404
- </tr>
405
-
406
-
407
- <tr valign='top'>
408
- <td class="attr-name">RANKINE</td>
409
- <td>=</td>
410
- <td class="attr-value">&#39;rankine&#39;</td>
411
- </tr>
412
-
413
- <tr valign='top'>
414
- <td>&nbsp;</td>
415
- <td colspan="2" class="attr-desc"></td>
416
- </tr>
417
-
418
-
419
- <tr valign='top'>
420
- <td class="attr-name">SCALES</td>
421
- <td>=</td>
422
- <td class="attr-value">[CELSIUS, FAHRENHEIT, KELVIN, RANKINE].freeze</td>
423
- </tr>
424
-
425
- <tr valign='top'>
426
- <td>&nbsp;</td>
427
- <td colspan="2" class="attr-desc"><p>A list of all currently supported scale values.</p></td>
428
- </tr>
429
-
430
-
431
97
  <tr valign='top'>
432
98
  <td class="attr-name">VERSION</td>
433
99
  <td>=</td>
434
- <td class="attr-value">&#39;0.2.1&#39;</td>
100
+ <td class="attr-value">&#39;0.2.2&#39;</td>
435
101
  </tr>
436
102
 
437
103
  <tr valign='top'>
@@ -445,779 +111,11 @@ Temperature[20, :celsius] - 10
445
111
 
446
112
 
447
113
 
448
- <!-- Section attributes -->
449
- <div class="sectiontitle">Attributes</div>
450
- <table border='0' cellpadding='5'>
451
-
452
- <tr valign='top'>
453
- <td class='attr-rw'>
454
- [R]
455
- </td>
456
- <td class='attr-name'>degrees</td>
457
- <td class='attr-desc'><p>Degrees of the temperature.</p></td>
458
- </tr>
459
-
460
- <tr valign='top'>
461
- <td class='attr-rw'>
462
- [R]
463
- </td>
464
- <td class='attr-name'>scale</td>
465
- <td class='attr-desc'><p>Scale of the temperature. Look at <a href="BasicTemperature.html#SCALES">SCALES</a> for possible values.</p></td>
466
- </tr>
467
-
468
- </table>
469
-
470
114
 
471
115
 
472
116
  <!-- Methods -->
473
117
 
474
- <div class="sectiontitle">Class Public methods</div>
475
-
476
- <div class="method">
477
- <div class="title method-title" id="method-c-5B-5D">
478
-
479
- <b>[](degrees:, scale:)<br />[](degrees, scale)</b>
480
-
481
- <a href="../classes/BasicTemperature.html#method-c-5B-5D" name="method-c-5B-5D" class="permalink">Link</a>
482
- </div>
483
-
484
-
485
- <div class="description">
486
- <p>Creates a new instance of <a href="Temperature.html"><code>Temperature</code></a>. Alias for <code>new</code>.</p>
487
- </div>
488
-
489
-
490
-
491
-
492
-
493
-
494
-
495
-
496
- <div class="sourcecode">
497
-
498
- <p class="source-link">
499
- Source:
500
- <a href="javascript:toggleSource('method-c-5B-5D_source')" id="l_method-c-5B-5D_source">show</a>
501
-
502
- </p>
503
- <div id="method-c-5B-5D_source" class="dyn-source">
504
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 215</span>
505
- <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>)
506
- <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>)
507
- <span class="ruby-keyword">end</span></pre>
508
- </div>
509
- </div>
510
-
511
- </div>
512
-
513
- <div class="method">
514
- <div class="title method-title" id="method-c-new">
515
-
516
- <b>new(degrees:, scale:)<br />new(degrees, scale)</b>
517
-
518
- <a href="../classes/BasicTemperature.html#method-c-new" name="method-c-new" class="permalink">Link</a>
519
- </div>
520
-
521
-
522
- <div class="description">
523
- <p>Creates a new instance of <a href="Temperature.html"><code>Temperature</code></a>. Is aliased as <code>[]</code>.</p>
524
- </div>
525
-
526
-
527
-
528
-
529
-
530
-
531
-
532
-
533
- <div class="sourcecode">
534
-
535
- <p class="source-link">
536
- Source:
537
- <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
538
-
539
- </p>
540
- <div id="method-c-new_source" class="dyn-source">
541
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 226</span>
542
- <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>)
543
- <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>)
544
-
545
- <span class="ruby-keyword">if</span> <span class="ruby-identifier">keyword_arguments</span>.<span class="ruby-identifier">any?</span>
546
- <span class="ruby-identifier">initialize_via_keywords_arguments</span>(<span class="ruby-identifier">keyword_arguments</span>)
547
- <span class="ruby-keyword">else</span> <span class="ruby-comment"># positional_arguments.any?</span>
548
- <span class="ruby-identifier">initialize_via_positional_arguments</span>(<span class="ruby-identifier">positional_arguments</span>)
549
- <span class="ruby-keyword">end</span>
550
- <span class="ruby-keyword">end</span></pre>
551
- </div>
552
- </div>
553
-
554
- </div>
555
-
556
-
557
118
 
558
- <div class="sectiontitle">Instance Public methods</div>
559
-
560
- <div class="method">
561
- <div class="title method-title" id="method-i-2B">
562
-
563
- <b>+(temperature)<br />+(numeric)</b>
564
-
565
- <a href="../classes/BasicTemperature.html#method-i-2B" name="method-i-2B" class="permalink">Link</a>
566
- </div>
567
-
568
-
569
- <div class="description">
570
- <p>Performs addition. Returns a new <a href="Temperature.html"><code>Temperature</code></a>.</p>
571
-
572
- <pre><code>Temperature[20, :celsius] + Temperature[10, :celsius]
573
- # =&gt; 30 °C
574
- </code></pre>
575
-
576
- <p>If the second temperature has a different scale, the first temperature is automatically converted to that scale before <code>degrees</code> addition.</p>
577
-
578
- <pre><code>Temperature[283.15, :kelvin] + Temperature[20, :celsius]
579
- # =&gt; 30 °C
580
- </code></pre>
581
-
582
- <p>Returned temperature will have the same scale as the second temperature.</p>
583
-
584
- <p>It is possible to add numerics.</p>
585
-
586
- <pre><code>Temperature[20, :celsius] + 10
587
- # =&gt; 30 °C
588
- </code></pre>
589
-
590
- <p>In such cases, returned temperature will have the same scale as the first temperature.</p>
591
-
592
- <p>Also <a href="https://ruby-doc.org/core/Numeric.html#method-i-coerce">Ruby coersion mechanism</a> is supported.</p>
593
-
594
- <pre><code>10 + Temperature[20, :celsius]
595
- # =&gt; 30 °C
596
- </code></pre>
597
- </div>
598
-
599
-
600
-
601
-
602
-
603
-
604
-
605
-
606
- <div class="sourcecode">
607
-
608
- <p class="source-link">
609
- Source:
610
- <a href="javascript:toggleSource('method-i-2B_source')" id="l_method-i-2B_source">show</a>
611
-
612
- </p>
613
- <div id="method-i-2B_source" class="dyn-source">
614
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 493</span>
615
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">+</span>(<span class="ruby-identifier">other</span>)
616
- <span class="ruby-identifier">assert_numeric_or_temperature!</span>(<span class="ruby-identifier">other</span>)
617
-
618
- <span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span> =
619
- <span class="ruby-keyword">case</span> <span class="ruby-identifier">other</span>
620
- <span class="ruby-keyword">when</span> <span class="ruby-constant">Numeric</span>
621
- [<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>]
622
- <span class="ruby-keyword">when</span> <span class="ruby-constant">BasicTemperature</span>
623
- [<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>]
624
- <span class="ruby-keyword">end</span>
625
-
626
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span>)
627
- <span class="ruby-keyword">end</span></pre>
628
- </div>
629
- </div>
630
-
631
- </div>
632
-
633
- <div class="method">
634
- <div class="title method-title" id="method-i-2D">
635
-
636
- <b>-(temperature)<br />-(numeric)</b>
637
-
638
- <a href="../classes/BasicTemperature.html#method-i-2D" name="method-i-2D" class="permalink">Link</a>
639
- </div>
640
-
641
-
642
- <div class="description">
643
- <p>Performs subtraction. Returns a new <a href="Temperature.html"><code>Temperature</code></a>.</p>
644
-
645
- <pre><code>Temperature[20, :celsius] - Temperature[10, :celsius]
646
- # =&gt; 10 °C
647
- </code></pre>
648
-
649
- <p>If the second temperature has a different scale, the first temperature is automatically converted to that scale before <code>degrees</code> subtraction.</p>
650
-
651
- <pre><code>Temperature[283.15, :kelvin] + Temperature[10, :celsius]
652
- # =&gt; 10 °C
653
- </code></pre>
654
-
655
- <p>Returned temperature will have the same scale as the second temperature.</p>
656
-
657
- <p>It is possible to subtract numerics.</p>
658
-
659
- <pre><code>Temperature[20, :celsius] - 10
660
- # =&gt; 10 °C
661
- </code></pre>
662
-
663
- <p>In such cases, returned temperature will have the same scale as the first temperature.</p>
664
-
665
- <p>Also <a href="https://ruby-doc.org/core/Numeric.html#method-i-coerce">Ruby coersion mechanism</a> is supported.</p>
666
-
667
- <pre><code>10 - Temperature[20, :celsius]
668
- # =&gt; -10 °C
669
- </code></pre>
670
- </div>
671
-
672
-
673
-
674
-
675
-
676
-
677
-
678
-
679
- <div class="sourcecode">
680
-
681
- <p class="source-link">
682
- Source:
683
- <a href="javascript:toggleSource('method-i-2D_source')" id="l_method-i-2D_source">show</a>
684
-
685
- </p>
686
- <div id="method-i-2D_source" class="dyn-source">
687
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 537</span>
688
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">-</span>(<span class="ruby-identifier">other</span>)
689
- <span class="ruby-keyword">self</span> <span class="ruby-operator">+</span> <span class="ruby-operator">-</span><span class="ruby-identifier">other</span>
690
- <span class="ruby-keyword">end</span></pre>
691
- </div>
692
- </div>
693
-
694
- </div>
695
-
696
- <div class="method">
697
- <div class="title method-title" id="method-i-2D-40">
698
-
699
- <b>-@</b>()
700
-
701
- <a href="../classes/BasicTemperature.html#method-i-2D-40" name="method-i-2D-40" class="permalink">Link</a>
702
- </div>
703
-
704
-
705
- <div class="description">
706
- <p>Returns a new <a href="Temperature.html"><code>Temperature</code></a> with negated <code>degrees</code>.</p>
707
-
708
- <pre><code>-Temperature[20, :celsius]
709
- # =&gt; -20 °C
710
- </code></pre>
711
- </div>
712
-
713
-
714
-
715
-
716
-
717
-
718
-
719
-
720
- <div class="sourcecode">
721
-
722
- <p class="source-link">
723
- Source:
724
- <a href="javascript:toggleSource('method-i-2D-40_source')" id="l_method-i-2D-40_source">show</a>
725
-
726
- </p>
727
- <div id="method-i-2D-40_source" class="dyn-source">
728
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 547</span>
729
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">-@</span>
730
- <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>)
731
- <span class="ruby-keyword">end</span></pre>
732
- </div>
733
- </div>
734
-
735
- </div>
736
-
737
- <div class="method">
738
- <div class="title method-title" id="method-i-3C-3D-3E">
739
-
740
- <b>&lt;=&gt;</b>(other)
741
-
742
- <a href="../classes/BasicTemperature.html#method-i-3C-3D-3E" name="method-i-3C-3D-3E" class="permalink">Link</a>
743
- </div>
744
-
745
-
746
- <div class="description">
747
- <p>Compares temperture with <code>other</code> temperature.</p>
748
-
749
- <p>Returns <code>0</code> if they are considered as equal.</p>
750
-
751
- <p>Two temperatures are considered as equal when they have the same amount of <code>degrees</code>.</p>
752
-
753
- <p>Returns <code>-1</code> if temperature is lower than <code>other</code> temperature.</p>
754
-
755
- <p>Returns <code>1</code> if temperature is higher than <code>other</code> temperature.</p>
756
-
757
- <p>If <code>other</code> temperature has a different scale, temperature is automatically converted to that scale before <code>degrees</code> comparison.</p>
758
-
759
- <pre><code>Temperature[20, :celsius] &lt;=&gt; Temperature[20, :celsius]
760
- # =&gt; 0
761
-
762
- Temperature[20, :celsius] &lt;=&gt; Temperature[293.15, :kelvin]
763
- # =&gt; 0
764
- </code></pre>
765
-
766
- <p>IMPORTANT!!!</p>
767
-
768
- <p>This method rounds <code>degrees</code> to the nearest value with a precision of 2 decimal digits.</p>
769
-
770
- <p>This means the following:</p>
771
-
772
- <pre><code>Temperature[20.020, :celsius] &lt;=&gt; Temperature[20.024, :celsius]
773
- # =&gt; 0
774
-
775
- Temperature[20.025, :celsius] &lt;=&gt; Temperature[20.029, :celsius]
776
- # =&gt; 0
777
-
778
- Temperature[20.024, :celsius] &lt;=&gt; Temperature[20.029, :celsius]
779
- # =&gt; -1
780
- </code></pre>
781
- </div>
782
-
783
-
784
-
785
-
786
-
787
-
788
-
789
-
790
- <div class="sourcecode">
791
-
792
- <p class="source-link">
793
- Source:
794
- <a href="javascript:toggleSource('method-i-3C-3D-3E_source')" id="l_method-i-3C-3D-3E_source">show</a>
795
-
796
- </p>
797
- <div id="method-i-3C-3D-3E_source" class="dyn-source">
798
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 457</span>
799
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">&lt;=&gt;</span>(<span class="ruby-identifier">other</span>)
800
- <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>)
801
-
802
- <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>)
803
- <span class="ruby-keyword">end</span></pre>
804
- </div>
805
- </div>
806
-
807
- </div>
808
-
809
- <div class="method">
810
- <div class="title method-title" id="method-i-set_degrees">
811
-
812
- <b>set_degrees</b>(degrees)
813
-
814
- <a href="../classes/BasicTemperature.html#method-i-set_degrees" name="method-i-set_degrees" class="permalink">Link</a>
815
- </div>
816
-
817
-
818
- <div class="description">
819
- <p>Returns a new <a href="Temperature.html"><code>Temperature</code></a> with updated <code>degrees</code>.</p>
820
-
821
- <pre><code>temperature = Temperature[0, :celsius]
822
- # =&gt; 0 °C
823
-
824
- new_temperature = temperature.set_degrees(15)
825
- # =&gt; 15 °C
826
- </code></pre>
827
- </div>
828
-
829
-
830
-
831
-
832
-
833
-
834
-
835
-
836
- <div class="sourcecode">
837
-
838
- <p class="source-link">
839
- Source:
840
- <a href="javascript:toggleSource('method-i-set_degrees_source')" id="l_method-i-set_degrees_source">show</a>
841
-
842
- </p>
843
- <div id="method-i-set_degrees_source" class="dyn-source">
844
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 246</span>
845
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_degrees</span>(<span class="ruby-identifier">degrees</span>)
846
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span>)
847
- <span class="ruby-keyword">end</span></pre>
848
- </div>
849
- </div>
850
-
851
- </div>
852
-
853
- <div class="method">
854
- <div class="title method-title" id="method-i-set_scale">
855
-
856
- <b>set_scale</b>(scale)
857
-
858
- <a href="../classes/BasicTemperature.html#method-i-set_scale" name="method-i-set_scale" class="permalink">Link</a>
859
- </div>
860
-
861
-
862
- <div class="description">
863
- <p>Returns a new <a href="Temperature.html"><code>Temperature</code></a> with updated <code>scale</code>.</p>
864
-
865
- <pre><code>temperature = Temperature[0, :celsius]
866
- # =&gt; 0 °C
867
-
868
- new_temperature = temperature.set_scale(:kelvin)
869
- # =&gt; 0 K
870
- </code></pre>
871
- </div>
872
-
873
-
874
-
875
-
876
-
877
-
878
-
879
-
880
- <div class="sourcecode">
881
-
882
- <p class="source-link">
883
- Source:
884
- <a href="javascript:toggleSource('method-i-set_scale_source')" id="l_method-i-set_scale_source">show</a>
885
-
886
- </p>
887
- <div id="method-i-set_scale_source" class="dyn-source">
888
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 261</span>
889
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">set_scale</span>(<span class="ruby-identifier">scale</span>)
890
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-identifier">scale</span>)
891
- <span class="ruby-keyword">end</span></pre>
892
- </div>
893
- </div>
894
-
895
- </div>
896
-
897
- <div class="method">
898
- <div class="title method-title" id="method-i-to_celsius">
899
-
900
- <b>to_celsius</b>()
901
-
902
- <a href="../classes/BasicTemperature.html#method-i-to_celsius" name="method-i-to_celsius" class="permalink">Link</a>
903
- </div>
904
-
905
-
906
- <div class="description">
907
- <p>Converts temperature to Celsius scale. If temperature is already in Celsius, returns current temperature object.</p>
908
-
909
- <p>Memoizes subsequent calls.</p>
910
-
911
- <p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
912
- <ol><li>
913
- <p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-fahrenheit.html">Celsius to Fahrenheit</a>.</p>
914
- </li><li>
915
- <p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-kelvin.html">Celsius to Kelvin</a>.</p>
916
- </li><li>
917
- <p><a href="https://www.rapidtables.com/convert/temperature/celsius-to-rankine.html">Celsius to Rankine</a>.</p>
918
- </li></ol>
919
-
920
- <pre><code>Temperature[0, :fahrenheit].to_celsius
921
- # =&gt; -17.78 °C
922
- </code></pre>
923
- </div>
924
-
925
-
926
-
927
-
928
-
929
-
930
-
931
-
932
- <div class="sourcecode">
933
-
934
- <p class="source-link">
935
- Source:
936
- <a href="javascript:toggleSource('method-i-to_celsius_source')" id="l_method-i-to_celsius_source">show</a>
937
-
938
- </p>
939
- <div id="method-i-to_celsius_source" class="dyn-source">
940
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 308</span>
941
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_celsius</span>
942
- <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> {
943
- <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>
944
-
945
- <span class="ruby-identifier">degrees</span> =
946
- <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
947
- <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
948
- (<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>)
949
- <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
950
- <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">-</span> <span class="ruby-value">273.15</span>
951
- <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
952
- (<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>)
953
- <span class="ruby-keyword">end</span>
954
-
955
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">CELSIUS</span>)
956
- })
957
- <span class="ruby-keyword">end</span></pre>
958
- </div>
959
- </div>
960
-
961
- </div>
962
-
963
- <div class="method">
964
- <div class="title method-title" id="method-i-to_fahrenheit">
965
-
966
- <b>to_fahrenheit</b>()
967
-
968
- <a href="../classes/BasicTemperature.html#method-i-to_fahrenheit" name="method-i-to_fahrenheit" class="permalink">Link</a>
969
- </div>
970
-
971
-
972
- <div class="description">
973
- <p>Converts temperature to Fahrenheit scale. If temperature is already in Fahrenheit, returns current temperature object.</p>
974
-
975
- <p>Memoizes subsequent calls.</p>
976
-
977
- <p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
978
- <ol><li>
979
- <p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-celsius.html">Fahrenheit to Celsius</a>.</p>
980
- </li><li>
981
- <p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-kelvin.html">Fahrenheit to Kelvin</a>.</p>
982
- </li><li>
983
- <p><a href="https://www.rapidtables.com/convert/temperature/fahrenheit-to-rankine.html">Fahrenheit to Rankine</a>.</p>
984
- </li></ol>
985
-
986
- <pre><code>Temperature[0, :celsius].to_fahrenheit
987
- # =&gt; 32 °F
988
- </code></pre>
989
- </div>
990
-
991
-
992
-
993
-
994
-
995
-
996
-
997
-
998
- <div class="sourcecode">
999
-
1000
- <p class="source-link">
1001
- Source:
1002
- <a href="javascript:toggleSource('method-i-to_fahrenheit_source')" id="l_method-i-to_fahrenheit_source">show</a>
1003
-
1004
- </p>
1005
- <div id="method-i-to_fahrenheit_source" class="dyn-source">
1006
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 340</span>
1007
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_fahrenheit</span>
1008
- <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> {
1009
- <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>
1010
-
1011
- <span class="ruby-identifier">degrees</span> =
1012
- <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
1013
- <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
1014
- <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>
1015
- <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
1016
- <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>
1017
- <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
1018
- <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">-</span> <span class="ruby-value">459.67</span>
1019
- <span class="ruby-keyword">end</span>
1020
-
1021
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">FAHRENHEIT</span>)
1022
- })
1023
- <span class="ruby-keyword">end</span></pre>
1024
- </div>
1025
- </div>
1026
-
1027
- </div>
1028
-
1029
- <div class="method">
1030
- <div class="title method-title" id="method-i-to_kelvin">
1031
-
1032
- <b>to_kelvin</b>()
1033
-
1034
- <a href="../classes/BasicTemperature.html#method-i-to_kelvin" name="method-i-to_kelvin" class="permalink">Link</a>
1035
- </div>
1036
-
1037
-
1038
- <div class="description">
1039
- <p>Converts temperature to Kelvin scale. If temperature is already in Kelvin, returns current</p>
1040
-
1041
- <pre><code>temperature object.
1042
- </code></pre>
1043
-
1044
- <p>Memoizes subsequent calls.</p>
1045
-
1046
- <p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
1047
- <ol><li>
1048
- <p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-celsius.html">Kelvin to Celsius</a>.</p>
1049
- </li><li>
1050
- <p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-fahrenheit.html">Kelvin to Fahrenheit</a>.</p>
1051
- </li><li>
1052
- <p><a href="https://www.rapidtables.com/convert/temperature/kelvin-to-rankine.html">Kelvin to Rankine</a>.</p>
1053
- </li></ol>
1054
-
1055
- <pre><code>Temperature[0, :kelvin].to_rankine
1056
- # =&gt; 0 °R
1057
- </code></pre>
1058
- </div>
1059
-
1060
-
1061
-
1062
-
1063
-
1064
-
1065
-
1066
-
1067
- <div class="sourcecode">
1068
-
1069
- <p class="source-link">
1070
- Source:
1071
- <a href="javascript:toggleSource('method-i-to_kelvin_source')" id="l_method-i-to_kelvin_source">show</a>
1072
-
1073
- </p>
1074
- <div id="method-i-to_kelvin_source" class="dyn-source">
1075
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 372</span>
1076
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_kelvin</span>
1077
- <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> {
1078
- <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>
1079
-
1080
- <span class="ruby-identifier">degrees</span> =
1081
- <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
1082
- <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
1083
- <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">+</span> <span class="ruby-value">273.15</span>
1084
- <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
1085
- (<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>)
1086
- <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
1087
- <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>)
1088
- <span class="ruby-keyword">end</span>
1089
-
1090
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">KELVIN</span>)
1091
- })
1092
- <span class="ruby-keyword">end</span></pre>
1093
- </div>
1094
- </div>
1095
-
1096
- </div>
1097
-
1098
- <div class="method">
1099
- <div class="title method-title" id="method-i-to_rankine">
1100
-
1101
- <b>to_rankine</b>()
1102
-
1103
- <a href="../classes/BasicTemperature.html#method-i-to_rankine" name="method-i-to_rankine" class="permalink">Link</a>
1104
- </div>
1105
-
1106
-
1107
- <div class="description">
1108
- <p>Converts temperature to Rankine scale. If temperature is already in Rankine, returns current temperature object.</p>
1109
-
1110
- <p>Memoizes subsequent calls.</p>
1111
-
1112
- <p>Conversion formulas are taken from <a href="https://www.rapidtables.com/">RapidTables</a>:</p>
1113
- <ol><li>
1114
- <p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-celsius.html">Rankine to Celsius</a>.</p>
1115
- </li><li>
1116
- <p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-fahrenheit.html">Rankine to Fahrenheit</a>.</p>
1117
- </li><li>
1118
- <p><a href="https://www.rapidtables.com/convert/temperature/rankine-to-kelvin.html">Rankine to Kelvin</a>.</p>
1119
- </li></ol>
1120
-
1121
- <pre><code>Temperature[0, :rankine].to_kelvin
1122
- # =&gt; 0 K
1123
- </code></pre>
1124
- </div>
1125
-
1126
-
1127
-
1128
-
1129
-
1130
-
1131
-
1132
-
1133
- <div class="sourcecode">
1134
-
1135
- <p class="source-link">
1136
- Source:
1137
- <a href="javascript:toggleSource('method-i-to_rankine_source')" id="l_method-i-to_rankine_source">show</a>
1138
-
1139
- </p>
1140
- <div id="method-i-to_rankine_source" class="dyn-source">
1141
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 404</span>
1142
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_rankine</span>
1143
- <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> {
1144
- <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>
1145
-
1146
- <span class="ruby-identifier">degrees</span> =
1147
- <span class="ruby-keyword">case</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">scale</span>
1148
- <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
1149
- (<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>)
1150
- <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
1151
- <span class="ruby-keyword">self</span>.<span class="ruby-identifier">degrees</span> <span class="ruby-operator">+</span> <span class="ruby-value">459.67</span>
1152
- <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
1153
- <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>)
1154
- <span class="ruby-keyword">end</span>
1155
-
1156
- <span class="ruby-constant">BasicTemperature</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">degrees</span>, <span class="ruby-constant">RANKINE</span>)
1157
- })
1158
- <span class="ruby-keyword">end</span></pre>
1159
- </div>
1160
- </div>
1161
-
1162
- </div>
1163
-
1164
- <div class="method">
1165
- <div class="title method-title" id="method-i-to_scale">
1166
-
1167
- <b>to_scale</b>(scale)
1168
-
1169
- <a href="../classes/BasicTemperature.html#method-i-to_scale" name="method-i-to_scale" class="permalink">Link</a>
1170
- </div>
1171
-
1172
-
1173
- <div class="description">
1174
- <p>Converts temperature to specific <code>scale</code>. If temperature is already in desired <code>scale</code>, returns current temperature object.</p>
1175
-
1176
- <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>
1177
-
1178
- <pre><code>Temperature[60, :fahrenheit].to_scale(:celsius)
1179
- # =&gt; 15.56 °C
1180
- </code></pre>
1181
- </div>
1182
-
1183
-
1184
-
1185
-
1186
-
1187
-
1188
-
1189
-
1190
- <div class="sourcecode">
1191
-
1192
- <p class="source-link">
1193
- Source:
1194
- <a href="javascript:toggleSource('method-i-to_scale_source')" id="l_method-i-to_scale_source">show</a>
1195
-
1196
- </p>
1197
- <div id="method-i-to_scale_source" class="dyn-source">
1198
- <pre><span class="ruby-comment"># File lib/basic_temperature.rb, line 277</span>
1199
- <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_scale</span>(<span class="ruby-identifier">scale</span>)
1200
- <span class="ruby-identifier">casted_scale</span> = <span class="ruby-identifier">cast_scale</span>(<span class="ruby-identifier">scale</span>)
1201
-
1202
- <span class="ruby-identifier">assert_valid_scale!</span>(<span class="ruby-identifier">casted_scale</span>)
1203
-
1204
- <span class="ruby-keyword">case</span> <span class="ruby-identifier">casted_scale</span>
1205
- <span class="ruby-keyword">when</span> <span class="ruby-constant">CELSIUS</span>
1206
- <span class="ruby-identifier">to_celsius</span>
1207
- <span class="ruby-keyword">when</span> <span class="ruby-constant">FAHRENHEIT</span>
1208
- <span class="ruby-identifier">to_fahrenheit</span>
1209
- <span class="ruby-keyword">when</span> <span class="ruby-constant">KELVIN</span>
1210
- <span class="ruby-identifier">to_kelvin</span>
1211
- <span class="ruby-keyword">when</span> <span class="ruby-constant">RANKINE</span>
1212
- <span class="ruby-identifier">to_rankine</span>
1213
- <span class="ruby-keyword">end</span>
1214
- <span class="ruby-keyword">end</span></pre>
1215
- </div>
1216
- </div>
1217
-
1218
- </div>
1219
-
1220
-
1221
119
 
1222
120
 
1223
121
  </div>