temperature 1.1.1 → 1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ === 1.2 ===
2
+ * 2 minor bug fix
3
+ * fix rakefile to do readme correctly
4
+ * fix a warning (thanks to Matt Nelson)
5
+ * 1 major enhancement
6
+ * Add Rankine units (thanks to Matt Nelson)
7
+
1
8
  === 1.1.1 2010-03-14
2
9
  * 1 minor bug fix
3
10
  * ensure relative humidity works if passed as a string
@@ -40,6 +40,11 @@ http://en.wikipedia.org/wiki/Dew_point#Closer_approximation
40
40
 
41
41
  sudo gem install temperature
42
42
 
43
+ == AUTHORS:
44
+
45
+ Sean Dague - maintainer
46
+ Matt Nelson
47
+
43
48
  == LICENSE:
44
49
 
45
50
  (The MIT License)
data/Rakefile CHANGED
@@ -16,6 +16,8 @@ $hoe = Hoe.spec 'temperature' do
16
16
  self.developer 'Sean Dague', 'sean@dague.net'
17
17
  self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
18
18
  self.rubyforge_name = "sdaguegems" # TODO this is default value
19
+ self.extra_rdoc_files = ["README.rdoc"]
20
+ self.readme_file = "README.rdoc"
19
21
  # self.extra_deps = [['activesupport','>= 2.0.2']]
20
22
 
21
23
  end
@@ -10,5 +10,5 @@ require 'temperature/string'
10
10
  # degrees 'F'. Yes, I realize this is US centric, but that's where I
11
11
  # live. In the future I'd like to auto detect that base on locale.
12
12
  module Temperature
13
- VERSION = "1.1.1"
13
+ VERSION = "1.2"
14
14
  end
@@ -18,6 +18,8 @@ class Numeric
18
18
  FOffset = 32
19
19
  # The offset between K and C
20
20
  KOffset = 273.15
21
+ # The offset between R and F
22
+ ROffset = 459.67
21
23
 
22
24
 
23
25
  # Is this a Farenheit temperature, returns a boolean
@@ -35,6 +37,10 @@ class Numeric
35
37
  return self.units == "K"
36
38
  end
37
39
 
40
+ def is_R?
41
+ return self.units == "R"
42
+ end
43
+
38
44
  # Convert the temperature to Farenheit. If it's already in F, it
39
45
  # returns itself.
40
46
  def to_F
@@ -42,6 +48,7 @@ class Numeric
42
48
  when "F" then return self
43
49
  when "C" then return self.c2f
44
50
  when "K" then return self.k2f
51
+ when "R" then return self.r2f
45
52
  end
46
53
  end
47
54
 
@@ -52,6 +59,7 @@ class Numeric
52
59
  when "F" then return self.f2c
53
60
  when "C" then return self
54
61
  when "K" then return self.k2c
62
+ when "R" then return self.r2c
55
63
  end
56
64
  end
57
65
 
@@ -62,8 +70,19 @@ class Numeric
62
70
  when "F" then return self.f2k
63
71
  when "C" then return self.c2k
64
72
  when "K" then return self
73
+ when "R" then return self.k2r
65
74
  end
66
75
  end
76
+
77
+ # Convert the temperature to Rankines.
78
+ def to_R
79
+ case self.units
80
+ when "F" then return self.f2r
81
+ when "C" then return self.c2r
82
+ when "K" then return self.k2r
83
+ when "R" then return self
84
+ end
85
+ end
67
86
 
68
87
  def c2f
69
88
  num = self * CScale + FOffset
@@ -97,6 +116,30 @@ class Numeric
97
116
  self.k2c.c2f
98
117
  end
99
118
 
119
+ def r2f
120
+ num = self - ROffset
121
+ num.units = "R"
122
+ return num
123
+ end
124
+
125
+ def f2r
126
+ num = self + ROffset
127
+ num.units = "R"
128
+ return num
129
+ end
130
+
131
+ def c2r
132
+ num = self * CScale + (ROffset + FOffset)
133
+ num.units = "R"
134
+ return num
135
+ end
136
+
137
+ def k2r
138
+ num = self * CScale
139
+ num.units = "R"
140
+ return num
141
+ end
142
+
100
143
  # Compute the dewpoint for the temperature given a relative
101
144
  # humidity. This is using the NOAA approximation for dewpoint
102
145
  # calculation -
@@ -116,7 +159,7 @@ class Numeric
116
159
  # not specified. Valid values are "C", "F", or "K" (R is not
117
160
  # currently support... no one really uses that anyway).
118
161
  def units
119
- if @units
162
+ if defined?(@units) && @units
120
163
  return @units
121
164
  else
122
165
  # this should auto detect the env, but for now, I live in the US
@@ -125,7 +168,7 @@ class Numeric
125
168
  end
126
169
 
127
170
  def units=(units)
128
- if units =~ /^(C|F|K)/
171
+ if units =~ /^(C|F|K|R)/
129
172
  @units = units
130
173
  end
131
174
  return @units
@@ -11,11 +11,11 @@ class String
11
11
  # be C, K, or F, and not have a space between the numer and the
12
12
  # units
13
13
  def to_degrees
14
- if self =~ /^(-?)(\d+)\.(\d+)(F|C|K)$/
14
+ if self =~ /^(-?)(\d+)\.(\d+)(F|C|K|R)$/
15
15
  tmp = "#{$1}#{$2}.#{$3}".to_f
16
16
  tmp.units = $4
17
17
  return tmp
18
- elsif self =~ /^(-?)(\d+)(F|C|K)$/
18
+ elsif self =~ /^(-?)(\d+)(F|C|K|R)$/
19
19
  tmp = "#{$1}#{$2}".to_f
20
20
  tmp.units = $3
21
21
  return tmp
@@ -35,16 +35,29 @@ class ConversionTest < Test::Unit::TestCase
35
35
  end
36
36
  end
37
37
 
38
+ def test_from_string_R
39
+ numbers = [32.1, 23, -14.1, -7]
40
+ numbers.each do |num|
41
+ temp = "#{num}R".to_degrees
42
+ assert_kind_of(Numeric, temp)
43
+ assert_equal(temp, num)
44
+ assert_equal(temp.units, "R")
45
+ assert(temp.is_R?)
46
+ end
47
+ end
48
+
38
49
  def test_convert
39
50
  f = [32.0, 212.0, -40.0, 32, 212, -40]
40
51
  c = [0.0, 100.0, -40.0, 0, 100, -40]
41
52
  k = [273.15, 373.15, 233.15, 273.15, 373.15, 233.15]
53
+ r = [491.67, 671.67, 419.67, 491.67, 671.67, 419.67]
42
54
 
43
55
  f.each_with_index do |n, i|
44
56
  temp = "#{n}F".to_degrees
45
57
  assert_in_delta(temp.to_C, c[i], 0.00001)
46
58
  assert_in_delta(temp.to_F, f[i], 0.00001)
47
59
  assert_in_delta(temp.to_K, k[i], 0.00001)
60
+ assert_in_delta(temp.to_R, r[i], 0.00001)
48
61
  end
49
62
 
50
63
  c.each_with_index do |n, i|
@@ -52,6 +65,7 @@ class ConversionTest < Test::Unit::TestCase
52
65
  assert_in_delta(temp.to_C, c[i], 0.00001)
53
66
  assert_in_delta(temp.to_F, f[i], 0.00001)
54
67
  assert_in_delta(temp.to_K, k[i], 0.00001)
68
+ assert_in_delta(temp.to_R, r[i], 0.00001)
55
69
  end
56
70
 
57
71
  k.each_with_index do |n, i|
@@ -59,6 +73,7 @@ class ConversionTest < Test::Unit::TestCase
59
73
  assert_in_delta(temp.to_C, c[i], 0.00001)
60
74
  assert_in_delta(temp.to_F, f[i], 0.00001)
61
75
  assert_in_delta(temp.to_K, k[i], 0.00001)
76
+ assert_in_delta(temp.to_R, r[i], 0.00001)
62
77
  end
63
78
  end
64
79
 
@@ -17,12 +17,14 @@ class NumTest < Test::Unit::TestCase
17
17
  f = [32.0, 212.0, -40.0, 32, 212, -40]
18
18
  c = [0.0, 100.0, -40.0, 0, 100, -40]
19
19
  k = [273.15, 373.15, 233.15, 273.15, 373.15, 233.15]
20
+ r = [491.67, 671.67, 419.67, 491.67, 671.67, 419.67]
20
21
 
21
22
  f.each_with_index do |n, i|
22
23
  temp = n
23
24
  assert_in_delta(temp.to_C, c[i], 0.00001)
24
25
  assert_in_delta(temp.to_F, f[i], 0.00001)
25
26
  assert_in_delta(temp.to_K, k[i], 0.00001)
27
+ assert_in_delta(temp.to_R, r[i], 0.00001)
26
28
  end
27
29
  end
28
30
  end
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temperature
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ hash: 11
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 2
9
+ version: "1.2"
5
10
  platform: ruby
6
11
  authors:
7
12
  - Sean Dague
@@ -9,39 +14,57 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-03-13 23:00:00 -05:00
17
+ date: 2010-11-01 00:00:00 -04:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: rubyforge
17
- type: :development
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
20
25
  requirements:
21
26
  - - ">="
22
27
  - !ruby/object:Gem::Version
28
+ hash: 9
29
+ segments:
30
+ - 2
31
+ - 0
32
+ - 3
23
33
  version: 2.0.3
24
- version:
34
+ type: :development
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: gemcutter
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
30
41
  requirements:
31
42
  - - ">="
32
43
  - !ruby/object:Gem::Version
44
+ hash: 19
45
+ segments:
46
+ - 0
47
+ - 3
48
+ - 0
33
49
  version: 0.3.0
34
- version:
50
+ type: :development
51
+ version_requirements: *id002
35
52
  - !ruby/object:Gem::Dependency
36
53
  name: hoe
37
- type: :development
38
- version_requirement:
39
- version_requirements: !ruby/object:Gem::Requirement
54
+ prerelease: false
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
40
57
  requirements:
41
58
  - - ">="
42
59
  - !ruby/object:Gem::Version
60
+ hash: 27
61
+ segments:
62
+ - 2
63
+ - 5
64
+ - 0
43
65
  version: 2.5.0
44
- version:
66
+ type: :development
67
+ version_requirements: *id003
45
68
  description: |-
46
69
  Temperature makes it easy to deal with temperatures in Ruby, but
47
70
  adding mixin methods to numbers and strings.
@@ -59,6 +82,7 @@ extra_rdoc_files:
59
82
  - History.txt
60
83
  - Manifest.txt
61
84
  - PostInstall.txt
85
+ - README.rdoc
62
86
  files:
63
87
  - COPYING
64
88
  - History.txt
@@ -89,21 +113,27 @@ rdoc_options:
89
113
  require_paths:
90
114
  - lib
91
115
  required_ruby_version: !ruby/object:Gem::Requirement
116
+ none: false
92
117
  requirements:
93
118
  - - ">="
94
119
  - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
95
123
  version: "0"
96
- version:
97
124
  required_rubygems_version: !ruby/object:Gem::Requirement
125
+ none: false
98
126
  requirements:
99
127
  - - ">="
100
128
  - !ruby/object:Gem::Version
129
+ hash: 3
130
+ segments:
131
+ - 0
101
132
  version: "0"
102
- version:
103
133
  requirements: []
104
134
 
105
135
  rubyforge_project: sdaguegems
106
- rubygems_version: 1.3.5
136
+ rubygems_version: 1.3.7
107
137
  signing_key:
108
138
  specification_version: 3
109
139
  summary: Temperature makes it easy to deal with temperatures in Ruby, but adding mixin methods to numbers and strings