m9t 0.1.8 → 0.1.9

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/lib/m9t.rb CHANGED
@@ -37,7 +37,7 @@ module M9t
37
37
  module VERSION #:nodoc:
38
38
  MAJOR = 0
39
39
  MINOR = 1
40
- TINY = 8
40
+ TINY = 9
41
41
 
42
42
  STRING = [MAJOR, MINOR, TINY].join('.')
43
43
  end
@@ -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)
@@ -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 in kelvin
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
@@ -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']
@@ -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']
@@ -27,8 +27,8 @@ class TestM9tTemperature < Test::Unit::TestCase
27
27
 
28
28
  # conversion constants
29
29
 
30
- def test_knot_conversion
31
- assert_in_delta(1.9438, M9t::Speed::MS_TO_KNOTS, 0.0001)
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 test_kmh
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 8
9
- version: 0.1.8
8
+ - 9
9
+ version: 0.1.9
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Yates