temperature 1.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.
- data/COPYING +21 -0
- data/README +45 -0
- data/Rakefile +133 -0
- data/docs/temperature/classes/Numeric.html +619 -0
- data/docs/temperature/classes/String.html +167 -0
- data/docs/temperature/created.rid +1 -0
- data/docs/temperature/files/COPYING.html +133 -0
- data/docs/temperature/files/README.html +156 -0
- data/docs/temperature/files/lib/temperature_rb.html +123 -0
- data/docs/temperature/fr_class_index.html +28 -0
- data/docs/temperature/fr_file_index.html +29 -0
- data/docs/temperature/fr_method_index.html +42 -0
- data/docs/temperature/index.html +24 -0
- data/docs/temperature/rdoc-style.css +208 -0
- data/lib/temperature.rb +174 -0
- data/test/convert_test.rb +69 -0
- data/test/coverage/index.html +100 -0
- data/test/coverage/lib-temperature_rb.html +300 -0
- data/test/dewpoint_test.rb +16 -0
- data/test/num_test.rb +32 -0
- metadata +76 -0
data/COPYING
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2009 Sean Dague <http://dague.net>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
= Overview
|
2
|
+
|
3
|
+
Temperature makes it easy to deal with temperatures in Ruby, but
|
4
|
+
adding mixin methods to numbers and strings.
|
5
|
+
|
6
|
+
This was inspired by using Ruby to manipulate data from my home
|
7
|
+
weather station, and wanting it to keep track of the units for me so
|
8
|
+
that I didn't have to think about that in code.
|
9
|
+
|
10
|
+
== Example
|
11
|
+
|
12
|
+
freezing_in_F = 32
|
13
|
+
freezing_in_C = freezing_in_F.to_C
|
14
|
+
|
15
|
+
boiling_in_C = 100
|
16
|
+
boiling_in_C.units = "C"
|
17
|
+
boiling_in_F = boiling_in_C.to_F
|
18
|
+
|
19
|
+
absolute_zero = "0K".to_degrees
|
20
|
+
absolute_zero_in_C = absolute_zero.to_C
|
21
|
+
absolute_zero_in_F = absolute_zero.to_F
|
22
|
+
|
23
|
+
There is also support to calculate dewpoint from relative humidity
|
24
|
+
based on the NOAA approximation documented here -
|
25
|
+
http://en.wikipedia.org/wiki/Dew_point#Closer_approximation
|
26
|
+
|
27
|
+
dewpoint = 32.dewpoint(45)
|
28
|
+
|
29
|
+
== Installation
|
30
|
+
|
31
|
+
First install the gem
|
32
|
+
|
33
|
+
gem install temperature
|
34
|
+
|
35
|
+
Then include it in your environment
|
36
|
+
|
37
|
+
require "temperature"
|
38
|
+
|
39
|
+
== Authors
|
40
|
+
|
41
|
+
Sean Dague <sean at dague dot net>
|
42
|
+
|
43
|
+
== License
|
44
|
+
|
45
|
+
This is released under an MIT license, see COPYING for full details.
|
data/Rakefile
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'rake/testtask'
|
4
|
+
require 'rake/rdoctask'
|
5
|
+
require 'rake/clean'
|
6
|
+
require 'rake/contrib/sshpublisher'
|
7
|
+
|
8
|
+
PKG_NAME = "temperature"
|
9
|
+
PKG_VERSION = "1.0"
|
10
|
+
|
11
|
+
$VERBOSE = nil
|
12
|
+
TEST_CHANGES_SINCE = Time.now - 600 # Recent tests = changed in last 10 minutes
|
13
|
+
|
14
|
+
desc "Run all the unit tests"
|
15
|
+
task :default => [ :test, :lines ]
|
16
|
+
|
17
|
+
desc "Run the unit tests in test"
|
18
|
+
Rake::TestTask.new(:test) { |t|
|
19
|
+
t.libs << "test"
|
20
|
+
t.test_files = FileList['test/*_test.rb']
|
21
|
+
t.verbose = true
|
22
|
+
}
|
23
|
+
|
24
|
+
# rcov code coverage
|
25
|
+
rcov_path = '/usr/bin/rcov'
|
26
|
+
rcov_test_output = "./test/coverage"
|
27
|
+
rcov_exclude = "interactive.rb,read_write.rb,fixtures"
|
28
|
+
|
29
|
+
# Add our created paths to the 'rake clobber' list
|
30
|
+
CLOBBER.include(rcov_test_output)
|
31
|
+
|
32
|
+
desc 'Removes all previous unit test coverage information'
|
33
|
+
task (:reset_unit_test_coverage) do |t|
|
34
|
+
rm_rf rcov_unit_test_output
|
35
|
+
mkdir rcov_unit_test_output
|
36
|
+
end
|
37
|
+
|
38
|
+
desc 'Run all unit tests with Rcov to measure coverage'
|
39
|
+
Rake::TestTask.new(:rcov) do |t|
|
40
|
+
t.libs << "test"
|
41
|
+
t.pattern = 'test/**/*_test.rb'
|
42
|
+
t.ruby_opts << rcov_path
|
43
|
+
t.ruby_opts << "-o #{rcov_test_output}"
|
44
|
+
t.ruby_opts << "-x #{rcov_exclude}"
|
45
|
+
t.verbose = true
|
46
|
+
end
|
47
|
+
|
48
|
+
# Generate the RDoc documentation
|
49
|
+
Rake::RDocTask.new(:doc) { |rdoc|
|
50
|
+
rdoc.main = 'README'
|
51
|
+
rdoc.rdoc_files.include('lib/**/*.rb', 'README')
|
52
|
+
rdoc.rdoc_files.include('COPYING')
|
53
|
+
rdoc.rdoc_dir = 'docs/temperature'
|
54
|
+
rdoc.title = "Temperature -- Temperature mixin for Numerics and Strings"
|
55
|
+
rdoc.options << "--include=examples --line-numbers --inline-source"
|
56
|
+
}
|
57
|
+
|
58
|
+
require 'rubygems'
|
59
|
+
require 'rubygems/gem_runner'
|
60
|
+
require 'rake/gempackagetask'
|
61
|
+
|
62
|
+
spec = Gem::Specification.new do |s|
|
63
|
+
s.name = "temperature"
|
64
|
+
s.version = PKG_VERSION
|
65
|
+
s.homepage = "http://github.com/sdague/temperature.rb"
|
66
|
+
s.platform = Gem::Platform::RUBY
|
67
|
+
s.summary = "A ruby mixin for making Numerics temperatures"
|
68
|
+
s.description = ""
|
69
|
+
|
70
|
+
s.files = FileList["{test,lib,docs,examples}/**/*"].to_a
|
71
|
+
s.files += ["Rakefile", "README", "COPYING" ]
|
72
|
+
s.require_path = "lib"
|
73
|
+
s.autorequire = "temperature"
|
74
|
+
s.has_rdoc = true
|
75
|
+
s.extra_rdoc_files = ["README", "COPYING" ]
|
76
|
+
s.rdoc_options.concat ['--main', 'README']
|
77
|
+
|
78
|
+
s.author = "Sean Dague"
|
79
|
+
s.email = "sean@dague.net"
|
80
|
+
end
|
81
|
+
|
82
|
+
Rake::GemPackageTask.new(spec) do |pkg|
|
83
|
+
pkg.gem_spec = spec
|
84
|
+
pkg.need_tar = true
|
85
|
+
pkg.need_zip = true
|
86
|
+
end
|
87
|
+
|
88
|
+
desc "Upload Docs to RubyForge"
|
89
|
+
task :publish_docs => [:doc] do
|
90
|
+
publisher = Rake::SshDirPublisher.new(
|
91
|
+
"sdague@rubyforge.org",
|
92
|
+
"/var/www/gforge-projects/sdaguegems",
|
93
|
+
"docs"
|
94
|
+
)
|
95
|
+
publisher.upload
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
desc "Publish the release files to RubyForge."
|
100
|
+
task :release => [ :package, :publish_docs ] do
|
101
|
+
require 'rubyforge'
|
102
|
+
packages = %w( gem tgz zip ).collect{ |ext| "pkg/#{PKG_NAME}-#{PKG_VERSION}.#{ext}" }
|
103
|
+
rubyforge = RubyForge.new
|
104
|
+
rubyforge.configure
|
105
|
+
rubyforge.login
|
106
|
+
rubyforge.scrape_project("sdaguegems")
|
107
|
+
rubyforge.add_release("sdaguegems", PKG_NAME, "v#{PKG_VERSION}", *packages)
|
108
|
+
end
|
109
|
+
|
110
|
+
desc 'Install the gem globally (requires sudo)'
|
111
|
+
task :install => :package do |t|
|
112
|
+
`sudo gem install pkg/temperature-#{PKG_VERSION}.gem`
|
113
|
+
end
|
114
|
+
|
115
|
+
task :lines do
|
116
|
+
lines = 0
|
117
|
+
codelines = 0
|
118
|
+
Dir.foreach("lib/") { |file_name|
|
119
|
+
next unless file_name =~ /.*rb/
|
120
|
+
|
121
|
+
f = File.open("lib/" + file_name)
|
122
|
+
|
123
|
+
while line = f.gets
|
124
|
+
lines += 1
|
125
|
+
next if line =~ /^\s*$/
|
126
|
+
next if line =~ /^\s*#/
|
127
|
+
codelines += 1
|
128
|
+
end
|
129
|
+
}
|
130
|
+
puts "\n------------------------------\n"
|
131
|
+
puts "Total Lines: #{lines}"
|
132
|
+
puts "Lines of Code: #{codelines}"
|
133
|
+
end
|
@@ -0,0 +1,619 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Numeric</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href=".././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Numeric</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../files/lib/temperature_rb.html">
|
59
|
+
lib/temperature.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
Object
|
69
|
+
</td>
|
70
|
+
</tr>
|
71
|
+
</table>
|
72
|
+
</div>
|
73
|
+
<!-- banner header -->
|
74
|
+
|
75
|
+
<div id="bodyContent">
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
<div id="contextContent">
|
80
|
+
|
81
|
+
<div id="description">
|
82
|
+
<p>
|
83
|
+
Temperature works as a mixin on both the <a href="Numeric.html">Numeric</a>
|
84
|
+
and <a href="String.html">String</a> classes. The idea is to make
|
85
|
+
manipulating temperatures as simple and natural as possible. If <a
|
86
|
+
href="Numeric.html#M000001">units</a> are not specified, they are assume to
|
87
|
+
be in degrees ‘F’. Yes, I realize this is US centric, but
|
88
|
+
that‘s where I live. In the future I‘d like to auto detect that
|
89
|
+
base on locale.
|
90
|
+
</p>
|
91
|
+
<p>
|
92
|
+
Example use:
|
93
|
+
</p>
|
94
|
+
<pre>
|
95
|
+
freezing_in_C = 32.to_C
|
96
|
+
|
97
|
+
num = 0
|
98
|
+
num.units = "C"
|
99
|
+
freezing_in_F = num.to_F
|
100
|
+
</pre>
|
101
|
+
|
102
|
+
</div>
|
103
|
+
|
104
|
+
|
105
|
+
</div>
|
106
|
+
|
107
|
+
<div id="method-list">
|
108
|
+
<h3 class="section-bar">Methods</h3>
|
109
|
+
|
110
|
+
<div class="name-list">
|
111
|
+
<a href="#M000009">c2f</a>
|
112
|
+
<a href="#M000011">c2k</a>
|
113
|
+
<a href="#M000015">dewpoint</a>
|
114
|
+
<a href="#M000010">f2c</a>
|
115
|
+
<a href="#M000013">f2k</a>
|
116
|
+
<a href="#M000004">is_C?</a>
|
117
|
+
<a href="#M000003">is_F?</a>
|
118
|
+
<a href="#M000005">is_K?</a>
|
119
|
+
<a href="#M000012">k2c</a>
|
120
|
+
<a href="#M000014">k2f</a>
|
121
|
+
<a href="#M000007">to_C</a>
|
122
|
+
<a href="#M000006">to_F</a>
|
123
|
+
<a href="#M000008">to_K</a>
|
124
|
+
<a href="#M000001">units</a>
|
125
|
+
<a href="#M000002">units=</a>
|
126
|
+
</div>
|
127
|
+
</div>
|
128
|
+
|
129
|
+
</div>
|
130
|
+
|
131
|
+
|
132
|
+
<!-- if includes -->
|
133
|
+
|
134
|
+
<div id="section">
|
135
|
+
|
136
|
+
|
137
|
+
<div id="constants-list">
|
138
|
+
<h3 class="section-bar">Constants</h3>
|
139
|
+
|
140
|
+
<div class="name-list">
|
141
|
+
<table summary="Constants">
|
142
|
+
<tr class="top-aligned-row context-row">
|
143
|
+
<td class="context-item-name">CScale</td>
|
144
|
+
<td>=</td>
|
145
|
+
<td class="context-item-value">1.8</td>
|
146
|
+
<td width="3em"> </td>
|
147
|
+
<td class="context-item-desc">
|
148
|
+
The scale factor between C and F
|
149
|
+
|
150
|
+
</td>
|
151
|
+
</tr>
|
152
|
+
<tr class="top-aligned-row context-row">
|
153
|
+
<td class="context-item-name">FOffset</td>
|
154
|
+
<td>=</td>
|
155
|
+
<td class="context-item-value">32</td>
|
156
|
+
<td width="3em"> </td>
|
157
|
+
<td class="context-item-desc">
|
158
|
+
The offset between C and F
|
159
|
+
|
160
|
+
</td>
|
161
|
+
</tr>
|
162
|
+
<tr class="top-aligned-row context-row">
|
163
|
+
<td class="context-item-name">KOffset</td>
|
164
|
+
<td>=</td>
|
165
|
+
<td class="context-item-value">273.15</td>
|
166
|
+
<td width="3em"> </td>
|
167
|
+
<td class="context-item-desc">
|
168
|
+
The offset between K and C
|
169
|
+
|
170
|
+
</td>
|
171
|
+
</tr>
|
172
|
+
</table>
|
173
|
+
</div>
|
174
|
+
</div>
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
<!-- if method_list -->
|
182
|
+
<div id="methods">
|
183
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
184
|
+
|
185
|
+
<div id="method-M000009" class="method-detail">
|
186
|
+
<a name="M000009"></a>
|
187
|
+
|
188
|
+
<div class="method-heading">
|
189
|
+
<a href="#M000009" class="method-signature">
|
190
|
+
<span class="method-name">c2f</span><span class="method-args">()</span>
|
191
|
+
</a>
|
192
|
+
</div>
|
193
|
+
|
194
|
+
<div class="method-description">
|
195
|
+
<p><a class="source-toggle" href="#"
|
196
|
+
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
197
|
+
<div class="method-source-code" id="M000009-source">
|
198
|
+
<pre>
|
199
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 98</span>
|
200
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">c2f</span>
|
201
|
+
<span class="ruby-identifier">num</span> = <span class="ruby-keyword kw">self</span> <span class="ruby-operator">*</span> <span class="ruby-constant">CScale</span> <span class="ruby-operator">+</span> <span class="ruby-constant">FOffset</span>
|
202
|
+
<span class="ruby-identifier">num</span>.<span class="ruby-identifier">units</span> = <span class="ruby-value str">"F"</span>
|
203
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">num</span>
|
204
|
+
<span class="ruby-keyword kw">end</span>
|
205
|
+
</pre>
|
206
|
+
</div>
|
207
|
+
</div>
|
208
|
+
</div>
|
209
|
+
|
210
|
+
<div id="method-M000011" class="method-detail">
|
211
|
+
<a name="M000011"></a>
|
212
|
+
|
213
|
+
<div class="method-heading">
|
214
|
+
<a href="#M000011" class="method-signature">
|
215
|
+
<span class="method-name">c2k</span><span class="method-args">()</span>
|
216
|
+
</a>
|
217
|
+
</div>
|
218
|
+
|
219
|
+
<div class="method-description">
|
220
|
+
<p><a class="source-toggle" href="#"
|
221
|
+
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
222
|
+
<div class="method-source-code" id="M000011-source">
|
223
|
+
<pre>
|
224
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 110</span>
|
225
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">c2k</span>
|
226
|
+
<span class="ruby-identifier">num</span> = <span class="ruby-keyword kw">self</span> <span class="ruby-operator">+</span> <span class="ruby-constant">KOffset</span>
|
227
|
+
<span class="ruby-identifier">num</span>.<span class="ruby-identifier">units</span> = <span class="ruby-value str">"K"</span>
|
228
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">num</span>
|
229
|
+
<span class="ruby-keyword kw">end</span>
|
230
|
+
</pre>
|
231
|
+
</div>
|
232
|
+
</div>
|
233
|
+
</div>
|
234
|
+
|
235
|
+
<div id="method-M000015" class="method-detail">
|
236
|
+
<a name="M000015"></a>
|
237
|
+
|
238
|
+
<div class="method-heading">
|
239
|
+
<a href="#M000015" class="method-signature">
|
240
|
+
<span class="method-name">dewpoint</span><span class="method-args">(rh)</span>
|
241
|
+
</a>
|
242
|
+
</div>
|
243
|
+
|
244
|
+
<div class="method-description">
|
245
|
+
<p>
|
246
|
+
Compute the <a href="Numeric.html#M000015">dewpoint</a> for the temperature
|
247
|
+
given a relative humidity. This is using the NOAA approximation for <a
|
248
|
+
href="Numeric.html#M000015">dewpoint</a> calculation - <a
|
249
|
+
href="http://en.wikipedia.org/wiki/Dew_point#Closer_approximation">en.wikipedia.org/wiki/Dew_point#Closer_approximation</a>
|
250
|
+
</p>
|
251
|
+
<p><a class="source-toggle" href="#"
|
252
|
+
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
253
|
+
<div class="method-source-code" id="M000015-source">
|
254
|
+
<pre>
|
255
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 134</span>
|
256
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">dewpoint</span>(<span class="ruby-identifier">rh</span>)
|
257
|
+
<span class="ruby-identifier">units</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">units</span>
|
258
|
+
<span class="ruby-identifier">temp</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">to_C</span>
|
259
|
+
<span class="ruby-identifier">e_sub_s</span> = <span class="ruby-value">6.112</span> <span class="ruby-operator">*</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">exp</span>((<span class="ruby-value">17.76</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">temp</span>) <span class="ruby-operator">/</span> (<span class="ruby-identifier">temp</span> <span class="ruby-operator">+</span> <span class="ruby-value">243.5</span>))
|
260
|
+
<span class="ruby-identifier">e</span> = <span class="ruby-identifier">rh</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">e_sub_s</span> <span class="ruby-operator">/</span> <span class="ruby-value">100</span>
|
261
|
+
<span class="ruby-identifier">dew</span> = <span class="ruby-value">243.5</span> <span class="ruby-operator">*</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">e</span> <span class="ruby-operator">/</span> <span class="ruby-value">6.112</span>) <span class="ruby-operator">/</span> (<span class="ruby-value">17.67</span> <span class="ruby-operator">-</span> <span class="ruby-constant">Math</span>.<span class="ruby-identifier">log</span>(<span class="ruby-identifier">e</span> <span class="ruby-operator">/</span> <span class="ruby-value">6.112</span>))
|
262
|
+
<span class="ruby-identifier">dew</span>.<span class="ruby-identifier">units</span> = <span class="ruby-value str">"C"</span>
|
263
|
+
<span class="ruby-identifier">final</span> = <span class="ruby-identifier">dew</span>.<span class="ruby-identifier">send</span>(<span class="ruby-node">"to_#{units}"</span>)
|
264
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">final</span>
|
265
|
+
<span class="ruby-keyword kw">end</span>
|
266
|
+
</pre>
|
267
|
+
</div>
|
268
|
+
</div>
|
269
|
+
</div>
|
270
|
+
|
271
|
+
<div id="method-M000010" class="method-detail">
|
272
|
+
<a name="M000010"></a>
|
273
|
+
|
274
|
+
<div class="method-heading">
|
275
|
+
<a href="#M000010" class="method-signature">
|
276
|
+
<span class="method-name">f2c</span><span class="method-args">()</span>
|
277
|
+
</a>
|
278
|
+
</div>
|
279
|
+
|
280
|
+
<div class="method-description">
|
281
|
+
<p><a class="source-toggle" href="#"
|
282
|
+
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
283
|
+
<div class="method-source-code" id="M000010-source">
|
284
|
+
<pre>
|
285
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 104</span>
|
286
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">f2c</span>
|
287
|
+
<span class="ruby-identifier">num</span> = (<span class="ruby-keyword kw">self</span> <span class="ruby-operator">-</span> <span class="ruby-constant">FOffset</span>) <span class="ruby-operator">/</span> <span class="ruby-constant">CScale</span>
|
288
|
+
<span class="ruby-identifier">num</span>.<span class="ruby-identifier">units</span> = <span class="ruby-value str">"C"</span>
|
289
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">num</span>
|
290
|
+
<span class="ruby-keyword kw">end</span>
|
291
|
+
</pre>
|
292
|
+
</div>
|
293
|
+
</div>
|
294
|
+
</div>
|
295
|
+
|
296
|
+
<div id="method-M000013" class="method-detail">
|
297
|
+
<a name="M000013"></a>
|
298
|
+
|
299
|
+
<div class="method-heading">
|
300
|
+
<a href="#M000013" class="method-signature">
|
301
|
+
<span class="method-name">f2k</span><span class="method-args">()</span>
|
302
|
+
</a>
|
303
|
+
</div>
|
304
|
+
|
305
|
+
<div class="method-description">
|
306
|
+
<p><a class="source-toggle" href="#"
|
307
|
+
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
308
|
+
<div class="method-source-code" id="M000013-source">
|
309
|
+
<pre>
|
310
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 122</span>
|
311
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">f2k</span>
|
312
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">f2c</span>.<span class="ruby-identifier">c2k</span>
|
313
|
+
<span class="ruby-keyword kw">end</span>
|
314
|
+
</pre>
|
315
|
+
</div>
|
316
|
+
</div>
|
317
|
+
</div>
|
318
|
+
|
319
|
+
<div id="method-M000004" class="method-detail">
|
320
|
+
<a name="M000004"></a>
|
321
|
+
|
322
|
+
<div class="method-heading">
|
323
|
+
<a href="#M000004" class="method-signature">
|
324
|
+
<span class="method-name">is_C?</span><span class="method-args">()</span>
|
325
|
+
</a>
|
326
|
+
</div>
|
327
|
+
|
328
|
+
<div class="method-description">
|
329
|
+
<p>
|
330
|
+
Is this a Celcius temperature, returns a boolean
|
331
|
+
</p>
|
332
|
+
<p><a class="source-toggle" href="#"
|
333
|
+
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
334
|
+
<div class="method-source-code" id="M000004-source">
|
335
|
+
<pre>
|
336
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 50</span>
|
337
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_C?</span>
|
338
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">units</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"C"</span>
|
339
|
+
<span class="ruby-keyword kw">end</span>
|
340
|
+
</pre>
|
341
|
+
</div>
|
342
|
+
</div>
|
343
|
+
</div>
|
344
|
+
|
345
|
+
<div id="method-M000003" class="method-detail">
|
346
|
+
<a name="M000003"></a>
|
347
|
+
|
348
|
+
<div class="method-heading">
|
349
|
+
<a href="#M000003" class="method-signature">
|
350
|
+
<span class="method-name">is_F?</span><span class="method-args">()</span>
|
351
|
+
</a>
|
352
|
+
</div>
|
353
|
+
|
354
|
+
<div class="method-description">
|
355
|
+
<p>
|
356
|
+
Is this a Farenheit temperature, returns a boolean
|
357
|
+
</p>
|
358
|
+
<p><a class="source-toggle" href="#"
|
359
|
+
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
360
|
+
<div class="method-source-code" id="M000003-source">
|
361
|
+
<pre>
|
362
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 45</span>
|
363
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_F?</span>
|
364
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">units</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"F"</span>
|
365
|
+
<span class="ruby-keyword kw">end</span>
|
366
|
+
</pre>
|
367
|
+
</div>
|
368
|
+
</div>
|
369
|
+
</div>
|
370
|
+
|
371
|
+
<div id="method-M000005" class="method-detail">
|
372
|
+
<a name="M000005"></a>
|
373
|
+
|
374
|
+
<div class="method-heading">
|
375
|
+
<a href="#M000005" class="method-signature">
|
376
|
+
<span class="method-name">is_K?</span><span class="method-args">()</span>
|
377
|
+
</a>
|
378
|
+
</div>
|
379
|
+
|
380
|
+
<div class="method-description">
|
381
|
+
<p>
|
382
|
+
Is this a Kelvin temperature, returns a boolean
|
383
|
+
</p>
|
384
|
+
<p><a class="source-toggle" href="#"
|
385
|
+
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
386
|
+
<div class="method-source-code" id="M000005-source">
|
387
|
+
<pre>
|
388
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 55</span>
|
389
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">is_K?</span>
|
390
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">units</span> <span class="ruby-operator">==</span> <span class="ruby-value str">"K"</span>
|
391
|
+
<span class="ruby-keyword kw">end</span>
|
392
|
+
</pre>
|
393
|
+
</div>
|
394
|
+
</div>
|
395
|
+
</div>
|
396
|
+
|
397
|
+
<div id="method-M000012" class="method-detail">
|
398
|
+
<a name="M000012"></a>
|
399
|
+
|
400
|
+
<div class="method-heading">
|
401
|
+
<a href="#M000012" class="method-signature">
|
402
|
+
<span class="method-name">k2c</span><span class="method-args">()</span>
|
403
|
+
</a>
|
404
|
+
</div>
|
405
|
+
|
406
|
+
<div class="method-description">
|
407
|
+
<p><a class="source-toggle" href="#"
|
408
|
+
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
409
|
+
<div class="method-source-code" id="M000012-source">
|
410
|
+
<pre>
|
411
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 116</span>
|
412
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">k2c</span>
|
413
|
+
<span class="ruby-identifier">num</span> = <span class="ruby-keyword kw">self</span> <span class="ruby-operator">-</span> <span class="ruby-constant">KOffset</span>
|
414
|
+
<span class="ruby-identifier">num</span>.<span class="ruby-identifier">units</span> = <span class="ruby-value str">"C"</span>
|
415
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-identifier">num</span>
|
416
|
+
<span class="ruby-keyword kw">end</span>
|
417
|
+
</pre>
|
418
|
+
</div>
|
419
|
+
</div>
|
420
|
+
</div>
|
421
|
+
|
422
|
+
<div id="method-M000014" class="method-detail">
|
423
|
+
<a name="M000014"></a>
|
424
|
+
|
425
|
+
<div class="method-heading">
|
426
|
+
<a href="#M000014" class="method-signature">
|
427
|
+
<span class="method-name">k2f</span><span class="method-args">()</span>
|
428
|
+
</a>
|
429
|
+
</div>
|
430
|
+
|
431
|
+
<div class="method-description">
|
432
|
+
<p><a class="source-toggle" href="#"
|
433
|
+
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
434
|
+
<div class="method-source-code" id="M000014-source">
|
435
|
+
<pre>
|
436
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 126</span>
|
437
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">k2f</span>
|
438
|
+
<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">k2c</span>.<span class="ruby-identifier">c2f</span>
|
439
|
+
<span class="ruby-keyword kw">end</span>
|
440
|
+
</pre>
|
441
|
+
</div>
|
442
|
+
</div>
|
443
|
+
</div>
|
444
|
+
|
445
|
+
<div id="method-M000007" class="method-detail">
|
446
|
+
<a name="M000007"></a>
|
447
|
+
|
448
|
+
<div class="method-heading">
|
449
|
+
<a href="#M000007" class="method-signature">
|
450
|
+
<span class="method-name">to_C</span><span class="method-args">()</span>
|
451
|
+
</a>
|
452
|
+
</div>
|
453
|
+
|
454
|
+
<div class="method-description">
|
455
|
+
<p>
|
456
|
+
Convert the temperature to Celcius. If it‘s already in C, it returns
|
457
|
+
itself.
|
458
|
+
</p>
|
459
|
+
<p><a class="source-toggle" href="#"
|
460
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
461
|
+
<div class="method-source-code" id="M000007-source">
|
462
|
+
<pre>
|
463
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 74</span>
|
464
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_C</span>
|
465
|
+
<span class="ruby-keyword kw">case</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">units</span>
|
466
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"F"</span><span class="ruby-operator">:</span>
|
467
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">f2c</span>
|
468
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"C"</span><span class="ruby-operator">:</span>
|
469
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
|
470
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"K"</span><span class="ruby-operator">:</span>
|
471
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">k2c</span>
|
472
|
+
<span class="ruby-keyword kw">end</span>
|
473
|
+
<span class="ruby-keyword kw">end</span>
|
474
|
+
</pre>
|
475
|
+
</div>
|
476
|
+
</div>
|
477
|
+
</div>
|
478
|
+
|
479
|
+
<div id="method-M000006" class="method-detail">
|
480
|
+
<a name="M000006"></a>
|
481
|
+
|
482
|
+
<div class="method-heading">
|
483
|
+
<a href="#M000006" class="method-signature">
|
484
|
+
<span class="method-name">to_F</span><span class="method-args">()</span>
|
485
|
+
</a>
|
486
|
+
</div>
|
487
|
+
|
488
|
+
<div class="method-description">
|
489
|
+
<p>
|
490
|
+
Convert the temperature to Farenheit. If it‘s already in F, it
|
491
|
+
returns itself.
|
492
|
+
</p>
|
493
|
+
<p><a class="source-toggle" href="#"
|
494
|
+
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
495
|
+
<div class="method-source-code" id="M000006-source">
|
496
|
+
<pre>
|
497
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 61</span>
|
498
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_F</span>
|
499
|
+
<span class="ruby-keyword kw">case</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">units</span>
|
500
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"F"</span><span class="ruby-operator">:</span>
|
501
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
|
502
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"C"</span><span class="ruby-operator">:</span>
|
503
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">c2f</span>
|
504
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"K"</span><span class="ruby-operator">:</span>
|
505
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">k2f</span>
|
506
|
+
<span class="ruby-keyword kw">end</span>
|
507
|
+
<span class="ruby-keyword kw">end</span>
|
508
|
+
</pre>
|
509
|
+
</div>
|
510
|
+
</div>
|
511
|
+
</div>
|
512
|
+
|
513
|
+
<div id="method-M000008" class="method-detail">
|
514
|
+
<a name="M000008"></a>
|
515
|
+
|
516
|
+
<div class="method-heading">
|
517
|
+
<a href="#M000008" class="method-signature">
|
518
|
+
<span class="method-name">to_K</span><span class="method-args">()</span>
|
519
|
+
</a>
|
520
|
+
</div>
|
521
|
+
|
522
|
+
<div class="method-description">
|
523
|
+
<p>
|
524
|
+
Convert the temperature to Kelvins. If it‘s already in K, it returns
|
525
|
+
itself.
|
526
|
+
</p>
|
527
|
+
<p><a class="source-toggle" href="#"
|
528
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
529
|
+
<div class="method-source-code" id="M000008-source">
|
530
|
+
<pre>
|
531
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 87</span>
|
532
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_K</span>
|
533
|
+
<span class="ruby-keyword kw">case</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">units</span>
|
534
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"F"</span><span class="ruby-operator">:</span>
|
535
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">f2k</span>
|
536
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"C"</span><span class="ruby-operator">:</span>
|
537
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">c2k</span>
|
538
|
+
<span class="ruby-keyword kw">when</span> <span class="ruby-value str">"K"</span><span class="ruby-operator">:</span>
|
539
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>
|
540
|
+
<span class="ruby-keyword kw">end</span>
|
541
|
+
<span class="ruby-keyword kw">end</span>
|
542
|
+
</pre>
|
543
|
+
</div>
|
544
|
+
</div>
|
545
|
+
</div>
|
546
|
+
|
547
|
+
<div id="method-M000001" class="method-detail">
|
548
|
+
<a name="M000001"></a>
|
549
|
+
|
550
|
+
<div class="method-heading">
|
551
|
+
<a href="#M000001" class="method-signature">
|
552
|
+
<span class="method-name">units</span><span class="method-args">()</span>
|
553
|
+
</a>
|
554
|
+
</div>
|
555
|
+
|
556
|
+
<div class="method-description">
|
557
|
+
<p>
|
558
|
+
The degree <a href="Numeric.html#M000001">units</a> the temperature is in.
|
559
|
+
This defaults to "F" if not specified. Valid values are
|
560
|
+
"C", "F", or "K" (R is not currently
|
561
|
+
support… no one really uses that anyway).
|
562
|
+
</p>
|
563
|
+
<p><a class="source-toggle" href="#"
|
564
|
+
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
565
|
+
<div class="method-source-code" id="M000001-source">
|
566
|
+
<pre>
|
567
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 28</span>
|
568
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">units</span>
|
569
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@units</span>
|
570
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@units</span>
|
571
|
+
<span class="ruby-keyword kw">else</span>
|
572
|
+
<span class="ruby-comment cmt"># this should auto detect the env, but for now, I live in the US</span>
|
573
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-value str">"F"</span>
|
574
|
+
<span class="ruby-keyword kw">end</span>
|
575
|
+
<span class="ruby-keyword kw">end</span>
|
576
|
+
</pre>
|
577
|
+
</div>
|
578
|
+
</div>
|
579
|
+
</div>
|
580
|
+
|
581
|
+
<div id="method-M000002" class="method-detail">
|
582
|
+
<a name="M000002"></a>
|
583
|
+
|
584
|
+
<div class="method-heading">
|
585
|
+
<a href="#M000002" class="method-signature">
|
586
|
+
<span class="method-name">units=</span><span class="method-args">(u)</span>
|
587
|
+
</a>
|
588
|
+
</div>
|
589
|
+
|
590
|
+
<div class="method-description">
|
591
|
+
<p><a class="source-toggle" href="#"
|
592
|
+
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
593
|
+
<div class="method-source-code" id="M000002-source">
|
594
|
+
<pre>
|
595
|
+
<span class="ruby-comment cmt"># File lib/temperature.rb, line 37</span>
|
596
|
+
<span class="ruby-keyword kw">def</span> <span class="ruby-identifier">units=</span>(<span class="ruby-identifier">u</span>)
|
597
|
+
<span class="ruby-keyword kw">if</span> <span class="ruby-identifier">u</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">/^(C|F|K)/</span>
|
598
|
+
<span class="ruby-ivar">@units</span> = <span class="ruby-identifier">u</span>
|
599
|
+
<span class="ruby-keyword kw">end</span>
|
600
|
+
<span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@units</span>
|
601
|
+
<span class="ruby-keyword kw">end</span>
|
602
|
+
</pre>
|
603
|
+
</div>
|
604
|
+
</div>
|
605
|
+
</div>
|
606
|
+
|
607
|
+
|
608
|
+
</div>
|
609
|
+
|
610
|
+
|
611
|
+
</div>
|
612
|
+
|
613
|
+
|
614
|
+
<div id="validator-badges">
|
615
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
616
|
+
</div>
|
617
|
+
|
618
|
+
</body>
|
619
|
+
</html>
|