m9t 0.3.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +6 -0
- data/.rspec +2 -0
- data/.travis.yml +13 -0
- data/Gemfile +2 -2
- data/README.md +28 -23
- data/Rakefile +6 -28
- data/lib/m9t.rb +5 -21
- data/lib/m9t/base.rb +86 -43
- data/lib/m9t/direction.rb +15 -23
- data/lib/m9t/distance.rb +9 -12
- data/lib/m9t/errors.rb +9 -0
- data/lib/m9t/i18n.rb +19 -11
- data/lib/m9t/pressure.rb +7 -13
- data/lib/m9t/speed.rb +12 -15
- data/lib/m9t/temperature.rb +13 -19
- data/lib/m9t/version.rb +4 -7
- data/locales/de.yml +68 -0
- data/locales/en.yml +13 -0
- data/m9t.gemspec +19 -17
- data/spec/base_spec.rb +79 -0
- data/spec/direction_spec.rb +195 -0
- data/spec/distance_spec.rb +127 -0
- data/spec/i18n_spec.rb +54 -0
- data/spec/pressure_spec.rb +22 -0
- data/spec/spec_helper.rb +20 -0
- data/spec/speed_spec.rb +102 -0
- data/spec/temperature_spec.rb +124 -0
- metadata +67 -47
- data/test/base_test.rb +0 -55
- data/test/direction_test.rb +0 -106
- data/test/distance_test.rb +0 -161
- data/test/i18n_test.rb +0 -30
- data/test/pressure_test.rb +0 -25
- data/test/speed_test.rb +0 -104
- data/test/temperature_test.rb +0 -111
- data/test/test_helper.rb +0 -17
@@ -0,0 +1,124 @@
|
|
1
|
+
require "m9t/temperature"
|
2
|
+
|
3
|
+
describe M9t::Temperature do
|
4
|
+
CONVERSIONS = [
|
5
|
+
[:kelvin, 100, 373.15],
|
6
|
+
[:fahrenheit, 100, 212.0],
|
7
|
+
]
|
8
|
+
|
9
|
+
context "constants" do
|
10
|
+
specify "absolute zero" do
|
11
|
+
expect(M9t::Temperature::ABSOLUTE_ZERO).to be_within(0.0001).of(-273.15)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "default options" do
|
16
|
+
specify "units: meters" do
|
17
|
+
expect(M9t::Temperature.options[:units]).to eq(:degrees)
|
18
|
+
end
|
19
|
+
|
20
|
+
specify "precision: 5" do
|
21
|
+
expect(M9t::Temperature.options[:precision]).to eq(5)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "class methods" do
|
26
|
+
context ".new" do
|
27
|
+
it "handles identity" do
|
28
|
+
expect(M9t::Temperature.new(45.0).value).to eq(45.0)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context ".measurement_name" do
|
33
|
+
it "is 'temperature'" do
|
34
|
+
expect(M9t::Temperature.measurement_name).to eq("temperature")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "conversion factories" do
|
39
|
+
CONVERSIONS.each do |unit, degrees, other|
|
40
|
+
specify ".#{unit}" do
|
41
|
+
expect(M9t::Temperature.send(unit, other).value).
|
42
|
+
to be_within(degrees.abs / 1000.0).of(degrees)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "conversions" do
|
48
|
+
context "from degrees" do
|
49
|
+
CONVERSIONS.each do |unit, degrees, other|
|
50
|
+
method = :"to_#{unit}"
|
51
|
+
specify method do
|
52
|
+
expect(M9t::Temperature.send(method, degrees)).to eq(other)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "to degrees" do
|
58
|
+
CONVERSIONS.each do |unit, degrees, other|
|
59
|
+
method = :"#{unit}_to_degrees"
|
60
|
+
specify method do
|
61
|
+
expect(M9t::Temperature.send(method, other)).to eq(degrees)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "conversions" do
|
69
|
+
context "from degrees" do
|
70
|
+
CONVERSIONS.each do |unit, degrees, other|
|
71
|
+
subject { M9t::Temperature.new(degrees) }
|
72
|
+
|
73
|
+
method = :"to_#{unit}"
|
74
|
+
specify method do
|
75
|
+
expect(subject.send(method)).to be_within(other.abs / 1000.0).of(other)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context "#to_s" do
|
82
|
+
subject { M9t::Temperature.new(135) }
|
83
|
+
|
84
|
+
specify "en" do
|
85
|
+
I18n.locale = :en
|
86
|
+
expect(subject.to_s).to eq("135.00000 degrees")
|
87
|
+
end
|
88
|
+
|
89
|
+
specify "it" do
|
90
|
+
I18n.locale = :it
|
91
|
+
expect(subject.to_s).to eq("135,00000 gradi")
|
92
|
+
end
|
93
|
+
|
94
|
+
specify "precision" do
|
95
|
+
I18n.locale = :en
|
96
|
+
expect(subject.to_s(precision: 0)).to eq("135 degrees")
|
97
|
+
end
|
98
|
+
|
99
|
+
specify "abbreviated, en" do
|
100
|
+
I18n.locale = :en
|
101
|
+
expect(subject.to_s(abbreviated: true, precision: 0)).
|
102
|
+
to eq("135°C")
|
103
|
+
end
|
104
|
+
|
105
|
+
specify "kelvin, en" do
|
106
|
+
I18n.locale = :en
|
107
|
+
expect(subject.to_s(units: :kelvin, precision: 2)).
|
108
|
+
to eq("408.15 kelvin")
|
109
|
+
end
|
110
|
+
|
111
|
+
specify "kelvin, it" do
|
112
|
+
I18n.locale = :it
|
113
|
+
expect(subject.to_s(units: :kelvin, precision: 2)).
|
114
|
+
to eq("408,15 kelvin")
|
115
|
+
end
|
116
|
+
|
117
|
+
specify "abbreviated, kelvin, it" do
|
118
|
+
I18n.locale = :it
|
119
|
+
expect(
|
120
|
+
subject.to_s(units: :kelvin, abbreviated: true, precision: 2)
|
121
|
+
).to eq("408,15K")
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
metadata
CHANGED
@@ -1,71 +1,95 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: m9t
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Joe Yates
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2021-05-30 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: rake
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: i18n
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 0.3.5
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 0.3.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: codeclimate-test-reporter
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.4.8
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 3.0.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.0.0
|
46
69
|
- !ruby/object:Gem::Dependency
|
47
70
|
name: simplecov
|
48
71
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
72
|
requirements:
|
51
|
-
- -
|
73
|
+
- - ">="
|
52
74
|
- !ruby/object:Gem::Version
|
53
75
|
version: '0'
|
54
76
|
type: :development
|
55
77
|
prerelease: false
|
56
78
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
79
|
requirements:
|
59
|
-
- -
|
80
|
+
- - ">="
|
60
81
|
- !ruby/object:Gem::Version
|
61
82
|
version: '0'
|
62
|
-
description:
|
63
|
-
|
83
|
+
description: 'Classes for handling basic measurement units: distance, direction, speed,
|
84
|
+
temperature and pressure'
|
64
85
|
email: joe.g.yates@gmail.com
|
65
86
|
executables: []
|
66
87
|
extensions: []
|
67
88
|
extra_rdoc_files: []
|
68
89
|
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
69
93
|
- GPL-LICENSE.txt
|
70
94
|
- Gemfile
|
71
95
|
- MIT-LICENSE.txt
|
@@ -75,57 +99,53 @@ files:
|
|
75
99
|
- lib/m9t/base.rb
|
76
100
|
- lib/m9t/direction.rb
|
77
101
|
- lib/m9t/distance.rb
|
102
|
+
- lib/m9t/errors.rb
|
78
103
|
- lib/m9t/i18n.rb
|
79
104
|
- lib/m9t/pressure.rb
|
80
105
|
- lib/m9t/speed.rb
|
81
106
|
- lib/m9t/temperature.rb
|
82
107
|
- lib/m9t/version.rb
|
108
|
+
- locales/de.yml
|
83
109
|
- locales/en.yml
|
84
110
|
- locales/it.yml
|
85
111
|
- m9t.gemspec
|
86
|
-
-
|
87
|
-
-
|
88
|
-
-
|
89
|
-
-
|
90
|
-
-
|
91
|
-
-
|
92
|
-
-
|
93
|
-
-
|
112
|
+
- spec/base_spec.rb
|
113
|
+
- spec/direction_spec.rb
|
114
|
+
- spec/distance_spec.rb
|
115
|
+
- spec/i18n_spec.rb
|
116
|
+
- spec/pressure_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/speed_spec.rb
|
119
|
+
- spec/temperature_spec.rb
|
94
120
|
homepage: https://github.com/joeyates/m9t
|
95
|
-
licenses:
|
121
|
+
licenses:
|
122
|
+
- MIT
|
123
|
+
metadata: {}
|
96
124
|
post_install_message:
|
97
125
|
rdoc_options: []
|
98
126
|
require_paths:
|
99
127
|
- lib
|
100
128
|
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
-
none: false
|
102
129
|
requirements:
|
103
|
-
- -
|
130
|
+
- - ">="
|
104
131
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
106
|
-
segments:
|
107
|
-
- 0
|
108
|
-
hash: 2996522648784473659
|
132
|
+
version: 2.4.0
|
109
133
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
-
none: false
|
111
134
|
requirements:
|
112
|
-
- -
|
135
|
+
- - ">="
|
113
136
|
- !ruby/object:Gem::Version
|
114
137
|
version: '0'
|
115
|
-
segments:
|
116
|
-
- 0
|
117
|
-
hash: 2996522648784473659
|
118
138
|
requirements: []
|
119
|
-
|
120
|
-
rubygems_version: 1.8.24
|
139
|
+
rubygems_version: 3.1.4
|
121
140
|
signing_key:
|
122
|
-
specification_version:
|
141
|
+
specification_version: 4
|
123
142
|
summary: Measurements and conversions library for Ruby
|
124
143
|
test_files:
|
125
|
-
-
|
126
|
-
-
|
127
|
-
-
|
128
|
-
-
|
129
|
-
-
|
130
|
-
-
|
131
|
-
-
|
144
|
+
- spec/base_spec.rb
|
145
|
+
- spec/direction_spec.rb
|
146
|
+
- spec/distance_spec.rb
|
147
|
+
- spec/i18n_spec.rb
|
148
|
+
- spec/pressure_spec.rb
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
- spec/speed_spec.rb
|
151
|
+
- spec/temperature_spec.rb
|
data/test/base_test.rb
DELETED
@@ -1,55 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path( 'test_helper', File.dirname( __FILE__ ) )
|
4
|
-
|
5
|
-
class SomeMeasurement
|
6
|
-
DEFAULT_OPTIONS = {:units => :foos, :abbreviated => false, :decimals => 1}
|
7
|
-
CONVERSIONS = {:foos => 1.0,
|
8
|
-
:bars => 1 / 42.0}
|
9
|
-
|
10
|
-
include M9t::Base
|
11
|
-
end
|
12
|
-
|
13
|
-
class SomeDerivedMeasurement < SomeMeasurement
|
14
|
-
end
|
15
|
-
|
16
|
-
class TestM9tBase < Test::Unit::TestCase
|
17
|
-
|
18
|
-
def setup
|
19
|
-
I18n.locale = :en
|
20
|
-
SomeMeasurement.reset_options!
|
21
|
-
end
|
22
|
-
|
23
|
-
# class methods
|
24
|
-
|
25
|
-
def test_class_method_missing_for_known_units
|
26
|
-
assert_in_delta(0.0714, SomeMeasurement.foos_to_bars(3.0), 0.001)
|
27
|
-
end
|
28
|
-
|
29
|
-
def test_class_method_missing_fails_on_unknown_units
|
30
|
-
assert_raise(RuntimeError) do
|
31
|
-
SomeMeasurement.bazs_to_bars(3.0)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# instance methods
|
36
|
-
|
37
|
-
def test_instance_method_missing_for_known_units
|
38
|
-
some = SomeMeasurement.new(3.0)
|
39
|
-
assert_in_delta(0.0714, some.to_bars(3.0), 0.001)
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_instance_method_missing_fails_on_unknown_units
|
43
|
-
some = SomeMeasurement.new(3.0)
|
44
|
-
assert_raise(RuntimeError) do
|
45
|
-
some.to_bazs(3.0)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
# derived classes
|
50
|
-
|
51
|
-
def test_derived_class_gets_options
|
52
|
-
assert_equal(SomeMeasurement.options, SomeDerivedMeasurement.options)
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
data/test/direction_test.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require File.expand_path( 'test_helper', File.dirname( __FILE__ ) )
|
4
|
-
|
5
|
-
class TestM9tDirection < Test::Unit::TestCase
|
6
|
-
|
7
|
-
def setup
|
8
|
-
I18n.locale = :en
|
9
|
-
M9t::Direction.reset_options!
|
10
|
-
end
|
11
|
-
|
12
|
-
# Basic use
|
13
|
-
def test_degrees
|
14
|
-
assert_equal(45, M9t::Direction.new(45).value)
|
15
|
-
end
|
16
|
-
|
17
|
-
# Class methods
|
18
|
-
|
19
|
-
# Base class
|
20
|
-
|
21
|
-
def test_measurement_name
|
22
|
-
assert_equal('direction', M9t::Direction.measurement_name)
|
23
|
-
end
|
24
|
-
|
25
|
-
def test_normalize
|
26
|
-
assert_equal(5, M9t::Direction.normalize(725))
|
27
|
-
assert_equal(5, M9t::Direction.normalize(-355))
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_default_options_set
|
31
|
-
assert_not_nil(M9t::Direction.options)
|
32
|
-
end
|
33
|
-
|
34
|
-
def test_default_option_abbreviated
|
35
|
-
assert(! M9t::Direction.options[:abbreviated])
|
36
|
-
end
|
37
|
-
|
38
|
-
def test_default_option_units
|
39
|
-
assert_equal(:degrees, M9t::Direction.options[:units])
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_to_degrees_identity
|
43
|
-
assert_equal(45, M9t::Direction.degrees_to_degrees(45))
|
44
|
-
end
|
45
|
-
|
46
|
-
def test_degrees_to_compass
|
47
|
-
assert_equal('N', M9t::Direction.degrees_to_compass(0))
|
48
|
-
assert_equal('NE', M9t::Direction.degrees_to_compass(42)) # Rounding up
|
49
|
-
assert_equal('E', M9t::Direction.degrees_to_compass(93)) # Rounding down
|
50
|
-
assert_equal('ESE', M9t::Direction.degrees_to_compass(113)) # 16ths
|
51
|
-
I18n.locale = :it
|
52
|
-
assert_equal('O', M9t::Direction.degrees_to_compass(270))
|
53
|
-
end
|
54
|
-
|
55
|
-
def test_compass
|
56
|
-
assert_equal(0, M9t::Direction.compass('N').value)
|
57
|
-
assert_equal(247.5, M9t::Direction.compass('WSW').value)
|
58
|
-
end
|
59
|
-
|
60
|
-
def test_compass_to_degrees
|
61
|
-
assert_equal(247.5, M9t::Direction.compass_to_degrees('WSW'))
|
62
|
-
end
|
63
|
-
|
64
|
-
# Instance methods
|
65
|
-
|
66
|
-
def test_to_s_not_abbreviated_singular
|
67
|
-
direction = M9t::Direction.new( 1 )
|
68
|
-
|
69
|
-
assert_equal '1 degree', direction.to_s
|
70
|
-
I18n.locale = :it
|
71
|
-
assert_equal '1 grado', direction.to_s
|
72
|
-
end
|
73
|
-
|
74
|
-
def test_to_s_not_abbreviated_plural
|
75
|
-
direction = M9t::Direction.new( 135 )
|
76
|
-
|
77
|
-
assert_equal '135 degrees', direction.to_s
|
78
|
-
I18n.locale = :it
|
79
|
-
assert_equal '135 gradi', direction.to_s
|
80
|
-
end
|
81
|
-
|
82
|
-
def test_to_s_abbreviated
|
83
|
-
direction = M9t::Direction.new( 135 )
|
84
|
-
|
85
|
-
assert_equal '135°', direction.to_s( :abbreviated => true )
|
86
|
-
end
|
87
|
-
|
88
|
-
def test_compass_units
|
89
|
-
direction = M9t::Direction.new( 225 )
|
90
|
-
|
91
|
-
assert_equal 'SW', direction.to_s( :units => :compass )
|
92
|
-
I18n.locale = :it
|
93
|
-
assert_equal 'SO', direction.to_s( :units => :compass )
|
94
|
-
end
|
95
|
-
|
96
|
-
def test_handles_string_leading_zero
|
97
|
-
assert_equal(10, M9t::Direction.new('010').value)
|
98
|
-
end
|
99
|
-
|
100
|
-
def test_to_compass
|
101
|
-
direction = M9t::Direction.new(0)
|
102
|
-
|
103
|
-
assert_equal('N', direction.to_compass)
|
104
|
-
end
|
105
|
-
|
106
|
-
end
|