temperature 1.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +8 -0
- data/Manifest.txt +24 -0
- data/PostInstall.txt +7 -0
- data/README.rdoc +66 -0
- data/Rakefile +20 -125
- data/config/website.yml +2 -0
- data/lib/temperature.rb +8 -168
- data/lib/temperature/numeric.rb +135 -0
- data/lib/temperature/string.rb +25 -0
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/script/txt2html +71 -0
- data/test/{convert_test.rb → test_convert.rb} +1 -4
- data/test/{dewpoint_test.rb → test_dewpoint.rb} +1 -4
- data/test/test_helper.rb +3 -0
- data/test/{num_test.rb → test_num.rb} +1 -4
- data/test/test_temperature.rb +11 -0
- data/website/index.html +11 -0
- data/website/index.txt +81 -0
- data/website/javascripts/rounded_corners_lite.inc.js +285 -0
- data/website/stylesheets/screen.css +159 -0
- data/website/template.html.erb +50 -0
- metadata +80 -34
- data/README +0 -45
- data/docs/temperature/classes/Numeric.html +0 -619
- data/docs/temperature/classes/String.html +0 -167
- data/docs/temperature/created.rid +0 -1
- data/docs/temperature/files/COPYING.html +0 -133
- data/docs/temperature/files/README.html +0 -156
- data/docs/temperature/files/lib/temperature_rb.html +0 -123
- data/docs/temperature/fr_class_index.html +0 -28
- data/docs/temperature/fr_file_index.html +0 -29
- data/docs/temperature/fr_method_index.html +0 -42
- data/docs/temperature/index.html +0 -24
- data/docs/temperature/rdoc-style.css +0 -208
- data/test/coverage/index.html +0 -100
- data/test/coverage/lib-temperature_rb.html +0 -300
data/History.txt
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
COPYING
|
2
|
+
History.txt
|
3
|
+
Manifest.txt
|
4
|
+
PostInstall.txt
|
5
|
+
README.rdoc
|
6
|
+
Rakefile
|
7
|
+
config/website.yml
|
8
|
+
lib/temperature.rb
|
9
|
+
lib/temperature/numeric.rb
|
10
|
+
lib/temperature/string.rb
|
11
|
+
script/console
|
12
|
+
script/destroy
|
13
|
+
script/generate
|
14
|
+
script/txt2html
|
15
|
+
test/test_convert.rb
|
16
|
+
test/test_dewpoint.rb
|
17
|
+
test/test_helper.rb
|
18
|
+
test/test_num.rb
|
19
|
+
test/test_temperature.rb
|
20
|
+
website/index.html
|
21
|
+
website/index.txt
|
22
|
+
website/javascripts/rounded_corners_lite.inc.js
|
23
|
+
website/stylesheets/screen.css
|
24
|
+
website/template.html.erb
|
data/PostInstall.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
= temperature
|
2
|
+
|
3
|
+
* http://github.com/sdague/temperature.rb
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
Temperature makes it easy to deal with temperatures in Ruby, but
|
8
|
+
adding mixin methods to numbers and strings.
|
9
|
+
|
10
|
+
This was inspired by using Ruby to manipulate data from my home
|
11
|
+
weather station, and wanting it to keep track of the units for me so
|
12
|
+
that I didn't have to think about that in code.
|
13
|
+
|
14
|
+
== FEATURES/PROBLEMS:
|
15
|
+
|
16
|
+
* Should autodetect what units are appropriate for the locale
|
17
|
+
|
18
|
+
== SYNOPSIS:
|
19
|
+
|
20
|
+
freezing_in_F = 32
|
21
|
+
freezing_in_C = freezing_in_F.to_C
|
22
|
+
|
23
|
+
boiling_in_C = 100
|
24
|
+
boiling_in_C.units = "C"
|
25
|
+
boiling_in_F = boiling_in_C.to_F
|
26
|
+
|
27
|
+
absolute_zero = "0K".to_degrees
|
28
|
+
absolute_zero_in_C = absolute_zero.to_C
|
29
|
+
absolute_zero_in_F = absolute_zero.to_F
|
30
|
+
|
31
|
+
There is also support to calculate dewpoint from relative humidity
|
32
|
+
based on the NOAA approximation documented here -
|
33
|
+
http://en.wikipedia.org/wiki/Dew_point#Closer_approximation
|
34
|
+
|
35
|
+
dewpoint = 32.dewpoint(45)
|
36
|
+
|
37
|
+
== REQUIREMENTS:
|
38
|
+
|
39
|
+
== INSTALL:
|
40
|
+
|
41
|
+
sudo gem install temperature
|
42
|
+
|
43
|
+
== LICENSE:
|
44
|
+
|
45
|
+
(The MIT License)
|
46
|
+
|
47
|
+
Copyright (c) 2010 Sean Dague
|
48
|
+
|
49
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
50
|
+
a copy of this software and associated documentation files (the
|
51
|
+
'Software'), to deal in the Software without restriction, including
|
52
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
53
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
54
|
+
permit persons to whom the Software is furnished to do so, subject to
|
55
|
+
the following conditions:
|
56
|
+
|
57
|
+
The above copyright notice and this permission notice shall be
|
58
|
+
included in all copies or substantial portions of the Software.
|
59
|
+
|
60
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
61
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
62
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
63
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
64
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
65
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
66
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
CHANGED
@@ -1,133 +1,28 @@
|
|
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
1
|
require 'rubygems'
|
59
|
-
|
60
|
-
require '
|
61
|
-
|
62
|
-
|
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
|
2
|
+
gem 'hoe', '>= 2.1.0'
|
3
|
+
require 'hoe'
|
4
|
+
require 'fileutils'
|
5
|
+
require './lib/temperature'
|
87
6
|
|
88
|
-
|
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
|
7
|
+
ENV['VERSION'] = Temperature::VERSION
|
97
8
|
|
9
|
+
Hoe.plugin :newgem
|
10
|
+
Hoe.plugin :website
|
11
|
+
# Hoe.plugin :cucumberfeatures
|
98
12
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
rubyforge.scrape_project("sdaguegems")
|
107
|
-
rubyforge.add_release("sdaguegems", PKG_NAME, "v#{PKG_VERSION}", *packages)
|
108
|
-
end
|
13
|
+
# Generate all the Rake tasks
|
14
|
+
# Run 'rake -T' to see list of generated tasks (from gem root directory)
|
15
|
+
$hoe = Hoe.spec 'temperature' do
|
16
|
+
self.developer 'Sean Dague', 'sean@dague.net'
|
17
|
+
self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
|
18
|
+
self.rubyforge_name = "sdaguegems" # TODO this is default value
|
19
|
+
# self.extra_deps = [['activesupport','>= 2.0.2']]
|
109
20
|
|
110
|
-
desc 'Install the gem globally (requires sudo)'
|
111
|
-
task :install => :package do |t|
|
112
|
-
`sudo gem install pkg/temperature-#{PKG_VERSION}.gem`
|
113
21
|
end
|
114
22
|
|
115
|
-
|
116
|
-
|
117
|
-
codelines = 0
|
118
|
-
Dir.foreach("lib/") { |file_name|
|
119
|
-
next unless file_name =~ /.*rb/
|
23
|
+
require 'newgem/tasks'
|
24
|
+
Dir['tasks/**/*.rake'].each { |t| load t }
|
120
25
|
|
121
|
-
|
122
|
-
|
123
|
-
|
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
|
26
|
+
# TODO - want other tests/tasks run by default? Add them to the list
|
27
|
+
# remove_task :default
|
28
|
+
# task :default => [:spec, :features]
|
data/config/website.yml
ADDED
data/lib/temperature.rb
CHANGED
@@ -1,174 +1,14 @@
|
|
1
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
2
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
|
+
|
4
|
+
require 'temperature/numeric'
|
5
|
+
require 'temperature/string'
|
6
|
+
|
1
7
|
# Temperature works as a mixin on both the Numeric and String classes.
|
2
8
|
# The idea is to make manipulating temperatures as simple and natural
|
3
9
|
# as possible. If units are not specified, they are assume to be in
|
4
10
|
# degrees 'F'. Yes, I realize this is US centric, but that's where I
|
5
11
|
# live. In the future I'd like to auto detect that base on locale.
|
6
|
-
|
7
|
-
|
8
|
-
#
|
9
|
-
# freezing_in_C = 32.to_C
|
10
|
-
#
|
11
|
-
# num = 0
|
12
|
-
# num.units = "C"
|
13
|
-
# freezing_in_F = num.to_F
|
14
|
-
|
15
|
-
class Numeric
|
16
|
-
@units
|
17
|
-
|
18
|
-
# The scale factor between C and F
|
19
|
-
CScale = 1.8
|
20
|
-
# The offset between C and F
|
21
|
-
FOffset = 32
|
22
|
-
# The offset between K and C
|
23
|
-
KOffset = 273.15
|
24
|
-
|
25
|
-
# The degree units the temperature is in. This defaults to "F" if
|
26
|
-
# not specified. Valid values are "C", "F", or "K" (R is not
|
27
|
-
# currently support... no one really uses that anyway).
|
28
|
-
def units
|
29
|
-
if @units
|
30
|
-
return @units
|
31
|
-
else
|
32
|
-
# this should auto detect the env, but for now, I live in the US
|
33
|
-
return "F"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def units=(u)
|
38
|
-
if u =~ /^(C|F|K)/
|
39
|
-
@units = u
|
40
|
-
end
|
41
|
-
return @units
|
42
|
-
end
|
43
|
-
|
44
|
-
# Is this a Farenheit temperature, returns a boolean
|
45
|
-
def is_F?
|
46
|
-
return self.units == "F"
|
47
|
-
end
|
48
|
-
|
49
|
-
# Is this a Celcius temperature, returns a boolean
|
50
|
-
def is_C?
|
51
|
-
return self.units == "C"
|
52
|
-
end
|
53
|
-
|
54
|
-
# Is this a Kelvin temperature, returns a boolean
|
55
|
-
def is_K?
|
56
|
-
return self.units == "K"
|
57
|
-
end
|
58
|
-
|
59
|
-
# Convert the temperature to Farenheit. If it's already in F, it
|
60
|
-
# returns itself.
|
61
|
-
def to_F
|
62
|
-
case self.units
|
63
|
-
when "F":
|
64
|
-
return self
|
65
|
-
when "C":
|
66
|
-
return self.c2f
|
67
|
-
when "K":
|
68
|
-
return self.k2f
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Convert the temperature to Celcius. If it's already in C, it
|
73
|
-
# returns itself.
|
74
|
-
def to_C
|
75
|
-
case self.units
|
76
|
-
when "F":
|
77
|
-
return self.f2c
|
78
|
-
when "C":
|
79
|
-
return self
|
80
|
-
when "K":
|
81
|
-
return self.k2c
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
# Convert the temperature to Kelvins. If it's already in K, it
|
86
|
-
# returns itself.
|
87
|
-
def to_K
|
88
|
-
case self.units
|
89
|
-
when "F":
|
90
|
-
return self.f2k
|
91
|
-
when "C":
|
92
|
-
return self.c2k
|
93
|
-
when "K":
|
94
|
-
return self
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def c2f
|
99
|
-
num = self * CScale + FOffset
|
100
|
-
num.units = "F"
|
101
|
-
return num
|
102
|
-
end
|
103
|
-
|
104
|
-
def f2c
|
105
|
-
num = (self - FOffset) / CScale
|
106
|
-
num.units = "C"
|
107
|
-
return num
|
108
|
-
end
|
109
|
-
|
110
|
-
def c2k
|
111
|
-
num = self + KOffset
|
112
|
-
num.units = "K"
|
113
|
-
return num
|
114
|
-
end
|
115
|
-
|
116
|
-
def k2c
|
117
|
-
num = self - KOffset
|
118
|
-
num.units = "C"
|
119
|
-
return num
|
120
|
-
end
|
121
|
-
|
122
|
-
def f2k
|
123
|
-
self.f2c.c2k
|
124
|
-
end
|
125
|
-
|
126
|
-
def k2f
|
127
|
-
self.k2c.c2f
|
128
|
-
end
|
129
|
-
|
130
|
-
# Compute the dewpoint for the temperature given a relative
|
131
|
-
# humidity. This is using the NOAA approximation for dewpoint
|
132
|
-
# calculation -
|
133
|
-
# http://en.wikipedia.org/wiki/Dew_point#Closer_approximation
|
134
|
-
def dewpoint(rh)
|
135
|
-
units = self.units
|
136
|
-
temp = self.to_C
|
137
|
-
e_sub_s = 6.112 * Math.exp((17.76 * temp) / (temp + 243.5))
|
138
|
-
e = rh * e_sub_s / 100
|
139
|
-
dew = 243.5 * Math.log(e / 6.112) / (17.67 - Math.log(e / 6.112))
|
140
|
-
dew.units = "C"
|
141
|
-
final = dew.send("to_#{units}")
|
142
|
-
return final
|
143
|
-
end
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
|
148
|
-
class String
|
149
|
-
|
150
|
-
# Parse a string that looks like a temperature into a temperature
|
151
|
-
# of the right units. It handles strings of the format
|
152
|
-
#
|
153
|
-
# 35.1C
|
154
|
-
# 72K
|
155
|
-
# -40F
|
156
|
-
#
|
157
|
-
# Decimals are support, as are negative numbers. The units must
|
158
|
-
# be C, K, or F, and not have a space between the numer and the
|
159
|
-
# units
|
160
|
-
def to_degrees
|
161
|
-
if self =~ /^(-?)(\d+)\.(\d+)(F|C|K)$/
|
162
|
-
tmp = "#{$1}#{$2}.#{$3}".to_f
|
163
|
-
tmp.units = $4
|
164
|
-
return tmp
|
165
|
-
elsif self =~ /^(-?)(\d+)(F|C|K)$/
|
166
|
-
tmp = "#{$1}#{$2}".to_f
|
167
|
-
tmp.units = $3
|
168
|
-
return tmp
|
169
|
-
end
|
170
|
-
end
|
171
|
-
|
172
|
-
|
12
|
+
module Temperature
|
13
|
+
VERSION = "1.1.0"
|
173
14
|
end
|
174
|
-
|