m9t 0.1.10 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
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 = 10
40
+ TINY = 11
41
41
 
42
42
  STRING = [MAJOR, MINOR, TINY].join('.')
43
43
  end
@@ -8,11 +8,12 @@ module M9t
8
8
  # Represents a distance
9
9
  class Distance
10
10
  DEFAULT_OPTIONS = {:units => :meters, :abbreviated => false, :precision => 5}
11
- KNOWN_UNITS = [:meters, :miles, :kilometers]
11
+ KNOWN_UNITS = [:meters, :kilometers, :feet, :miles]
12
12
 
13
13
  # Conversions
14
- METERS_PER_MILE = 1609.344
15
- METERS_PER_KILOMETER = 1000.0
14
+ KILOMETER = 1000.0
15
+ MILE = 1609.344
16
+ FOOT = 0.3048
16
17
 
17
18
  include M9t::Base
18
19
 
@@ -25,12 +26,17 @@ module M9t
25
26
 
26
27
  # Accepts a value in kilometers and returns the equivalent M9t::Distance
27
28
  def kilometers(km, options = {})
28
- new(km.to_f * METERS_PER_KILOMETER, options)
29
+ new(km.to_f * KILOMETER, options)
29
30
  end
30
31
 
31
32
  # Accepts a value in miles and returns the equivalent M9t::Distance
32
33
  def miles(miles, options = {})
33
- new(miles.to_f * METERS_PER_MILE, options)
34
+ new(miles.to_f * MILE, options)
35
+ end
36
+
37
+ # Accepts a value in miles and returns the equivalent M9t::Distance
38
+ def feet(feet, options = {})
39
+ new(feet.to_f * FOOT, options)
34
40
  end
35
41
 
36
42
  # Identity conversion. Simply returns the supplied number
@@ -40,12 +46,17 @@ module M9t
40
46
 
41
47
  # Converts meters into kilometers
42
48
  def to_kilometers(meters)
43
- meters.to_f / METERS_PER_KILOMETER
49
+ meters.to_f / KILOMETER
44
50
  end
45
51
 
46
52
  # Converts meters into miles
47
53
  def to_miles(meters)
48
- meters.to_f / METERS_PER_MILE
54
+ meters.to_f / MILE
55
+ end
56
+
57
+ # Converts meters into miles
58
+ def to_feet(meters)
59
+ meters.to_f / FOOT
49
60
  end
50
61
 
51
62
  end
@@ -62,6 +73,11 @@ module M9t
62
73
  self.class.to_miles(@value)
63
74
  end
64
75
 
76
+ # Returns the value converted to feet
77
+ def to_feet
78
+ self.class.to_feet(@value)
79
+ end
80
+
65
81
  end
66
82
 
67
83
  end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ require 'rubygems' if RUBY_VERSION < '1.9'
3
+ require 'i18n'
4
+ require File.join(File.expand_path(File.dirname(__FILE__)), 'base')
5
+
6
+ module M9t
7
+
8
+ # Represents atmospheric (or other) pressure
9
+ class Pressure
10
+ DEFAULT_OPTIONS = {:units => :bar, :abbreviated => false, :precision => 5}
11
+ KNOWN_UNITS = [:bar, :pascals, :hectopascals, :kilopascals, :inches_of_mercury]
12
+
13
+ # Conversions
14
+ PASCAL = 0.00001
15
+ HECTOPASCAL = 100.0 * PASCAL
16
+ KILOPASCAL = 1000.0 * PASCAL
17
+ INCH_OF_MERCURY = 3386.389 * PASCAL
18
+
19
+ include M9t::Base
20
+
21
+ def Pressure.hectopascals(hectopascals)
22
+ new(hectopascals * HECTOPASCAL)
23
+ end
24
+
25
+ def Pressure.inches_of_mercury(inches_of_mercury)
26
+ new(inches_of_mercury * INCH_OF_MERCURY)
27
+ end
28
+
29
+ def Pressure.to_inches_of_mercury(bar)
30
+ bar / INCH_OF_MERCURY
31
+ end
32
+
33
+ def Pressure.to_bar(bar)
34
+ bar.to_f
35
+ end
36
+
37
+ def to_inches_of_mercury
38
+ Pressure.to_inches_of_mercury(@value)
39
+ end
40
+
41
+ def to_bar
42
+ Pressure.to_bar(@value)
43
+ end
44
+
45
+ end
46
+
47
+ end
@@ -12,10 +12,10 @@ module M9t
12
12
 
13
13
  # Conversions
14
14
  SECONDS_PER_HOUR = 60.0 * 60
15
- MS_TO_KMH = SECONDS_PER_HOUR / M9t::Distance::METERS_PER_KILOMETER
16
- MS_TO_MPH = SECONDS_PER_HOUR / M9t::Distance::METERS_PER_MILE
15
+ MS_TO_KMH = SECONDS_PER_HOUR / M9t::Distance::KILOMETER
16
+ MS_TO_MPH = SECONDS_PER_HOUR / M9t::Distance::MILE
17
17
  KNOTS_TO_KMH = 1.852
18
- MS_TO_KNOTS = 1.0 / (KNOTS_TO_KMH / SECONDS_PER_HOUR * M9t::Distance::METERS_PER_KILOMETER)
18
+ MS_TO_KNOTS = 1.0 / (KNOTS_TO_KMH / SECONDS_PER_HOUR * M9t::Distance::KILOMETER)
19
19
 
20
20
  include M9t::Base
21
21
 
@@ -22,6 +22,11 @@ en:
22
22
  zero: miles
23
23
  one: mile
24
24
  other: miles
25
+ feet:
26
+ full:
27
+ one: foot
28
+ other: feet
29
+ abbreviated: ft
25
30
  direction:
26
31
  degrees:
27
32
  full:
@@ -22,6 +22,10 @@ it:
22
22
  zero: miglia
23
23
  one: miglio
24
24
  other: miglia
25
+ feet:
26
+ full:
27
+ one: foot
28
+ other: feet
25
29
  direction:
26
30
  degrees:
27
31
  full:
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'rubygems' if RUBY_VERSION < '1.9'
5
+ require 'test/unit'
6
+ require File.join(File.expand_path(File.dirname(__FILE__) + '/../lib'), 'm9t')
7
+
8
+ class TestM9tDistance < Test::Unit::TestCase
9
+
10
+ def setup
11
+ I18n.locale = :en
12
+ M9t::Pressure.reset_options!
13
+ end
14
+
15
+ # Basic use
16
+ def test_bar
17
+ assert_equal(1.0, M9t::Pressure.new(1.0).value)
18
+ end
19
+
20
+ def test_hectopascals
21
+ assert_equal(0.001, M9t::Pressure.hectopascals(1.0).value)
22
+ end
23
+
24
+ def test_inches_of_mercury
25
+ assert_in_delta(0.03386, M9t::Pressure.inches_of_mercury(1.0).value, 0.00001)
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 10
9
- version: 0.1.10
8
+ - 11
9
+ version: 0.1.11
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joe Yates
@@ -45,12 +45,14 @@ files:
45
45
  - COPYING
46
46
  - Rakefile
47
47
  - lib/m9t.rb
48
+ - lib/m9t/pressure.rb
48
49
  - lib/m9t/speed.rb
49
50
  - lib/m9t/base.rb
50
51
  - lib/m9t/direction.rb
51
52
  - lib/m9t/distance.rb
52
53
  - lib/m9t/i18n.rb
53
54
  - lib/m9t/temperature.rb
55
+ - test/pressure_test.rb
54
56
  - test/direction_test.rb
55
57
  - test/i18n_test.rb
56
58
  - test/distance_test.rb