m9t 0.1.4 → 0.1.5
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 +1 -1
- data/lib/m9t/speed.rb +6 -0
- data/test/speed_test.rb +8 -0
- metadata +2 -2
data/lib/m9t.rb
CHANGED
data/lib/m9t/speed.rb
CHANGED
@@ -14,6 +14,7 @@ module M9t
|
|
14
14
|
SECONDS_PER_HOUR = 60.0 * 60
|
15
15
|
MS_TO_KMH = SECONDS_PER_HOUR / M9t::Distance::METERS_PER_KILOMETER
|
16
16
|
MS_TO_MPH = SECONDS_PER_HOUR / M9t::Distance::METERS_PER_MILE
|
17
|
+
MS_TO_KNOTS = 1.852 / SECONDS_PER_HOUR * M9t::Distance::METERS_PER_KILOMETER
|
17
18
|
|
18
19
|
include M9t::Base
|
19
20
|
|
@@ -44,6 +45,11 @@ module M9t
|
|
44
45
|
mps.to_f / MS_TO_MPH
|
45
46
|
end
|
46
47
|
|
48
|
+
# Converts meters per second to knots
|
49
|
+
def to_knots(mps)
|
50
|
+
mps.to_f / MS_TO_KNOTS
|
51
|
+
end
|
52
|
+
|
47
53
|
end
|
48
54
|
|
49
55
|
alias :to_meters_per_second :value
|
data/test/speed_test.rb
CHANGED
@@ -59,6 +59,8 @@ class TestM9tSpeed < Test::Unit::TestCase
|
|
59
59
|
|
60
60
|
def test_to_s
|
61
61
|
assert_equal '135.00000 meters per second', M9t::Speed.new(135).to_s
|
62
|
+
I18n.locale = :it
|
63
|
+
assert_equal '135,00000 metri al second', M9t::Speed.new(135).to_s
|
62
64
|
end
|
63
65
|
|
64
66
|
def test_to_s_precision
|
@@ -69,4 +71,10 @@ class TestM9tSpeed < Test::Unit::TestCase
|
|
69
71
|
assert_equal '135m/s', M9t::Speed.new(135, :abbreviated => true, :precision => 0).to_s
|
70
72
|
end
|
71
73
|
|
74
|
+
def test_to_s_knots
|
75
|
+
assert_equal '262 knots', M9t::Speed.new(135, {:units => :knots, :precision => 0}).to_s
|
76
|
+
I18n.locale = :it
|
77
|
+
assert_equal '262 nodi', M9t::Speed.new(135, {:units => :knots, :precision => 0}).to_s
|
78
|
+
end
|
79
|
+
|
72
80
|
end
|