m9t 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/m9t.rb +1 -1
- data/lib/m9t/distance.rb +5 -0
- data/lib/m9t/temperature.rb +29 -1
- data/locales/en.yml +6 -0
- data/locales/it.yml +6 -0
- data/test/temperature_test.rb +22 -3
- metadata +2 -2
data/lib/m9t.rb
CHANGED
data/lib/m9t/distance.rb
CHANGED
@@ -18,6 +18,11 @@ module M9t
|
|
18
18
|
|
19
19
|
class << self
|
20
20
|
|
21
|
+
# Alias for new
|
22
|
+
def meters(*args)
|
23
|
+
new(*args)
|
24
|
+
end
|
25
|
+
|
21
26
|
# Accepts a value in kilometers and returns the equivalent M9t::Distance
|
22
27
|
def kilometers(km, options = {})
|
23
28
|
new(km.to_f * METERS_PER_KILOMETER, options)
|
data/lib/m9t/temperature.rb
CHANGED
@@ -18,21 +18,45 @@ module M9t
|
|
18
18
|
|
19
19
|
class << self
|
20
20
|
|
21
|
+
# Alias for new
|
22
|
+
def degrees(*args)
|
23
|
+
new(*args)
|
24
|
+
end
|
25
|
+
|
21
26
|
# Accepts a value in kelvin and returns the equivalent M9t::Temperature
|
22
27
|
def kelvin(kelvin, options = {})
|
23
28
|
new(kelvin.to_f + ABSOLUTE_ZERO, options)
|
24
29
|
end
|
25
30
|
|
31
|
+
def fahrenheit(fahrenheit, options = {})
|
32
|
+
new(fahrenheit_to_degrees(fahrenheit), options)
|
33
|
+
end
|
34
|
+
|
26
35
|
# Identity conversion. Simply returns the supplied number
|
27
36
|
def to_degrees(degrees)
|
28
37
|
degrees.to_f
|
29
38
|
end
|
30
39
|
|
31
|
-
# Converts degrees
|
40
|
+
# Converts degrees to kelvin
|
32
41
|
def to_kelvin(degrees)
|
33
42
|
degrees.to_f - ABSOLUTE_ZERO
|
34
43
|
end
|
35
44
|
|
45
|
+
# Converts degrees to Fahrenheit
|
46
|
+
def to_fahrenheit(degrees)
|
47
|
+
degrees.to_f * 9.0 / 5.0 + 32
|
48
|
+
end
|
49
|
+
|
50
|
+
# Converts kelvin to degrees
|
51
|
+
def kelvin_to_degrees(kelvin)
|
52
|
+
kelvin.to_f + ABSOLUTE_ZERO
|
53
|
+
end
|
54
|
+
|
55
|
+
# Converts Fahrenheit to degrees
|
56
|
+
def fahrenheit_to_degrees(fahrenheit)
|
57
|
+
fahrenheit.to_f - 32 * 5.0 / 9.0
|
58
|
+
end
|
59
|
+
|
36
60
|
end
|
37
61
|
|
38
62
|
alias :to_degrees :value
|
@@ -42,6 +66,10 @@ module M9t
|
|
42
66
|
self.class.to_kelvin(@value)
|
43
67
|
end
|
44
68
|
|
69
|
+
def to_fahrenheit
|
70
|
+
self.class.to_fahrenheit(@value)
|
71
|
+
end
|
72
|
+
|
45
73
|
end
|
46
74
|
|
47
75
|
end
|
data/locales/en.yml
CHANGED
@@ -48,5 +48,11 @@ en:
|
|
48
48
|
one: degree
|
49
49
|
other: degrees
|
50
50
|
abbreviated: °C
|
51
|
+
kelvin:
|
52
|
+
full:
|
53
|
+
zero: kelvin
|
54
|
+
one: kelvin
|
55
|
+
other: kelvin
|
56
|
+
abbreviated: K
|
51
57
|
direction:
|
52
58
|
sectors: ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N']
|
data/locales/it.yml
CHANGED
@@ -48,5 +48,11 @@ it:
|
|
48
48
|
one: grado
|
49
49
|
other: gradi
|
50
50
|
abbreviated: °C
|
51
|
+
kelvin:
|
52
|
+
full:
|
53
|
+
zero: kelvin
|
54
|
+
one: kelvin
|
55
|
+
other: kelvin
|
56
|
+
abbreviated: K
|
51
57
|
direction:
|
52
58
|
sectors: ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSO', 'SO', 'OSO', 'O', 'ONO', 'NO', 'NNO', 'N']
|
data/test/temperature_test.rb
CHANGED
@@ -27,8 +27,8 @@ class TestM9tTemperature < Test::Unit::TestCase
|
|
27
27
|
|
28
28
|
# conversion constants
|
29
29
|
|
30
|
-
def
|
31
|
-
assert_in_delta(
|
30
|
+
def test_kelvin_offset
|
31
|
+
assert_in_delta(-273.15, M9t::Temperature::ABSOLUTE_ZERO, 0.0001)
|
32
32
|
end
|
33
33
|
|
34
34
|
# input conversions
|
@@ -37,12 +37,20 @@ class TestM9tTemperature < Test::Unit::TestCase
|
|
37
37
|
assert_in_delta(-273.15, M9t::Temperature.kelvin(0).value, 0.0001)
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_class_fahrenheit
|
41
|
+
assert_in_delta(-17.7777, M9t::Temperature.fahrenheit(0).value, 0.0001)
|
42
|
+
end
|
43
|
+
|
40
44
|
# output conversions
|
41
45
|
|
42
46
|
def test_class_to_kelvin
|
43
47
|
assert_in_delta(273.15, M9t::Temperature.to_kelvin(0), 0.0001)
|
44
48
|
end
|
45
49
|
|
50
|
+
def test_class_to_fahrenheit
|
51
|
+
assert_in_delta(32, M9t::Temperature.to_fahrenheit(0), 0.0001)
|
52
|
+
end
|
53
|
+
|
46
54
|
# Instance methods
|
47
55
|
|
48
56
|
# new
|
@@ -53,10 +61,14 @@ class TestM9tTemperature < Test::Unit::TestCase
|
|
53
61
|
|
54
62
|
# output conversions
|
55
63
|
|
56
|
-
def
|
64
|
+
def test_to_kelvin
|
57
65
|
assert_equal(373.15, M9t::Temperature.new(100).to_kelvin)
|
58
66
|
end
|
59
67
|
|
68
|
+
def test_to_fahrenheit
|
69
|
+
assert_equal(212, M9t::Temperature.new(100).to_fahrenheit)
|
70
|
+
end
|
71
|
+
|
60
72
|
# to_s
|
61
73
|
|
62
74
|
def test_to_s
|
@@ -71,6 +83,13 @@ class TestM9tTemperature < Test::Unit::TestCase
|
|
71
83
|
|
72
84
|
def test_to_s_abbreviated
|
73
85
|
assert_equal '135°C', M9t::Temperature.new(135, :abbreviated => true, :precision => 0).to_s
|
86
|
+
assert_equal '408.15K', M9t::Temperature.new(135, :units => :kelvin, :abbreviated => true, :precision => 2).to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_to_s_kelvin
|
90
|
+
assert_equal '373.15 kelvin', M9t::Temperature.new(100, :units => :kelvin, :precision => 2).to_s
|
91
|
+
I18n.locale = :it
|
92
|
+
assert_equal '373,15 kelvin', M9t::Temperature.new(100, :units => :kelvin, :precision => 2).to_s
|
74
93
|
end
|
75
94
|
|
76
95
|
end
|