m9t 0.3.6 → 1.0.0
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.
- checksums.yaml +5 -5
- data/.rspec +1 -2
- data/.travis.yml +1 -0
- data/Gemfile +2 -3
- data/Rakefile +5 -4
- data/lib/m9t.rb +1 -1
- data/lib/m9t/base.rb +10 -11
- data/lib/m9t/direction.rb +11 -14
- data/lib/m9t/distance.rb +1 -2
- data/lib/m9t/errors.rb +7 -5
- data/lib/m9t/i18n.rb +9 -10
- data/lib/m9t/pressure.rb +1 -2
- data/lib/m9t/speed.rb +2 -3
- data/lib/m9t/temperature.rb +1 -2
- data/lib/m9t/version.rb +4 -4
- data/m9t.gemspec +16 -17
- data/spec/base_spec.rb +17 -19
- data/spec/direction_spec.rb +80 -71
- data/spec/distance_spec.rb +38 -41
- data/spec/i18n_spec.rb +15 -18
- data/spec/pressure_spec.rb +5 -8
- data/spec/spec_helper.rb +6 -6
- data/spec/speed_spec.rb +26 -29
- data/spec/temperature_spec.rb +32 -35
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1e9e5be154c21f5d10e86c7c6f906f5bdd2287c56797965f8430c12fbcee09b2
|
4
|
+
data.tar.gz: c23bd6fe57b417fc46680c9c91dfe7517ea0833e1ec76f6cd959df5466a02028
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 12f3a7e3428384abfa69f90c2d7210dff7ba94494ae82e14b0be892159de160722ad60fd16502e68b699e228a1206af122246ff3c2062c24e14d942d0e90831f
|
7
|
+
data.tar.gz: 0b2fd9ec442f4dcaf8d992a3d301404d91c4ce6da76972affe6c40deb152f034cc6cc76a752ad921a7328748d3e4b05a40ee50edfe7675e687856fc5dcac58f1
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
#!/usr/bin/env rake
|
2
|
-
require 'bundler/gem_tasks'
|
3
|
-
require 'rspec/core/rake_task'
|
4
2
|
|
5
|
-
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rspec/core/rake_task"
|
5
|
+
|
6
|
+
task default: :spec
|
6
7
|
|
7
8
|
RSpec::Core::RakeTask.new do |t|
|
8
|
-
t.pattern =
|
9
|
+
t.pattern = "spec/**/*_spec.rb"
|
9
10
|
end
|
data/lib/m9t.rb
CHANGED
data/lib/m9t/base.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require 'm9t/i18n'
|
1
|
+
require "m9t/errors"
|
2
|
+
require "m9t/i18n"
|
4
3
|
|
5
4
|
module M9t
|
6
5
|
module Base
|
@@ -82,15 +81,15 @@ module M9t
|
|
82
81
|
@options
|
83
82
|
end
|
84
83
|
|
85
|
-
# Reloads the class
|
84
|
+
# Reloads the class"s default options
|
86
85
|
def reset_options!
|
87
86
|
@options = self::DEFAULT_OPTIONS.clone
|
88
87
|
end
|
89
88
|
|
90
89
|
# The name used for i18n translations
|
91
|
-
# M9t::Distance =>
|
90
|
+
# M9t::Distance => "distance"
|
92
91
|
def measurement_name
|
93
|
-
name.split(
|
92
|
+
name.split("::")[-1].downcase
|
94
93
|
end
|
95
94
|
|
96
95
|
def default_unit
|
@@ -145,20 +144,20 @@ module M9t
|
|
145
144
|
key = i18n_key(options)
|
146
145
|
unit = I18n.t(key, count: value_in_units)
|
147
146
|
|
148
|
-
"#{localized_value}%s#{unit}" % (options[:abbreviated] ?
|
147
|
+
"#{localized_value}%s#{unit}" % (options[:abbreviated] ? "" : " ")
|
149
148
|
end
|
150
149
|
|
151
150
|
private
|
152
151
|
|
153
152
|
def i18n_key(options = {})
|
154
|
-
key =
|
155
|
-
options[:abbreviated] ?
|
153
|
+
key = "units.#{self.class.measurement_name}.#{options[:units]}"
|
154
|
+
key += options[:abbreviated] ? ".abbreviated" : ".full"
|
156
155
|
key
|
157
156
|
end
|
158
157
|
|
159
158
|
def units_error(units)
|
160
|
-
known = self.class::CONVERSIONS.keys.collect(&:to_s).join(
|
161
|
-
fail M9t::UnitError,
|
159
|
+
known = self.class::CONVERSIONS.keys.collect(&:to_s).join(", ")
|
160
|
+
fail M9t::UnitError, %Q(Unknown units "#{units}". Known: #{known})
|
162
161
|
end
|
163
162
|
|
164
163
|
def extract_to(name)
|
data/lib/m9t/direction.rb
CHANGED
@@ -1,11 +1,10 @@
|
|
1
|
-
|
2
|
-
require 'm9t/base'
|
1
|
+
require "m9t/base"
|
3
2
|
|
4
3
|
module M9t
|
5
4
|
# Represents a geographical direction
|
6
5
|
class Direction
|
7
6
|
DEFAULT_OPTIONS = {units: :degrees, abbreviated: false, decimals: 5}
|
8
|
-
CONVERSIONS
|
7
|
+
CONVERSIONS = {
|
9
8
|
degrees: 1.0,
|
10
9
|
compass: nil,
|
11
10
|
}
|
@@ -18,20 +17,20 @@ module M9t
|
|
18
17
|
|
19
18
|
class << self
|
20
19
|
# Given a value in degrees, returns the nearest (localized) compass direction
|
21
|
-
# M9t::Directions.to_compass(42) =>
|
20
|
+
# M9t::Directions.to_compass(42) => "NE"
|
22
21
|
def degrees_to_compass(degrees)
|
23
22
|
sector = (normalize(degrees) / COMPASS_SECTOR_DEGREES).round
|
24
|
-
I18n.t(self.measurement_name +
|
23
|
+
I18n.t(self.measurement_name + ".sectors")[sector]
|
25
24
|
end
|
26
25
|
|
27
26
|
def compass_to_degrees(compass_direction)
|
28
27
|
compass(compass_direction).to_f
|
29
28
|
end
|
30
29
|
|
31
|
-
# Accepts a localized compass direction (e.g.
|
32
|
-
# M9t::Direction.compass(
|
30
|
+
# Accepts a localized compass direction (e.g. "N") and returns the equivalent M9t::Direction
|
31
|
+
# M9t::Direction.compass("NE") => #<M9t::Direction:0x000000014a438618 @value=45.0>
|
33
32
|
def compass(compass_direction)
|
34
|
-
sector = I18n.t(self.measurement_name +
|
33
|
+
sector = I18n.t(self.measurement_name + ".sectors").find_index(compass_direction)
|
35
34
|
raise "Compass direction '#{compass_direction}' not recognised" if sector.nil?
|
36
35
|
new(sector.to_f * COMPASS_SECTOR_DEGREES)
|
37
36
|
end
|
@@ -39,13 +38,11 @@ module M9t
|
|
39
38
|
# Reduce directions in degrees to the range [0, 360)
|
40
39
|
# M9t::Direction.normalize(1000) => 280.0
|
41
40
|
def normalize(degrees)
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
when degrees >= CIRCLE
|
46
|
-
normalize(degrees - CIRCLE)
|
41
|
+
remainder = degrees.remainder(CIRCLE)
|
42
|
+
if remainder < 0
|
43
|
+
remainder + CIRCLE
|
47
44
|
else
|
48
|
-
|
45
|
+
remainder
|
49
46
|
end
|
50
47
|
end
|
51
48
|
end
|
data/lib/m9t/distance.rb
CHANGED
data/lib/m9t/errors.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
|
2
|
-
class M9t
|
3
|
-
|
1
|
+
module M9t
|
2
|
+
# Base class for all M9t exceptions
|
3
|
+
class M9tError < StandardError
|
4
|
+
end
|
4
5
|
|
5
|
-
# Raised when a M9t class receives an unrecogized ':units' value
|
6
|
-
class
|
6
|
+
# Raised when a M9t class receives an unrecogized ':units' value
|
7
|
+
class UnitError < M9t::M9tError
|
8
|
+
end
|
7
9
|
end
|
data/lib/m9t/i18n.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
|
-
|
2
|
-
require 'i18n'
|
1
|
+
require "i18n"
|
3
2
|
|
4
3
|
locales_path = File.expand_path(
|
5
|
-
File.join(
|
4
|
+
File.join("..", "..", "locales"), File.dirname(__FILE__)
|
6
5
|
)
|
7
6
|
I18n.load_path += Dir.glob("#{ locales_path }/*.yml")
|
8
7
|
I18n.reload!
|
@@ -16,19 +15,19 @@ I18n.reload!
|
|
16
15
|
module I18n
|
17
16
|
# Handle non-English numerical separators
|
18
17
|
# with I18n.locale = :it,
|
19
|
-
# I18n.localize_float(5.23) =>
|
18
|
+
# I18n.localize_float(5.23) => "5,23000"
|
20
19
|
def I18n.localize_float(float, options = {})
|
21
|
-
format = options[:format] ||
|
20
|
+
format = options[:format] || "%f"
|
22
21
|
english = format % float
|
23
|
-
integers, decimal = english.split(
|
24
|
-
integers ||=
|
22
|
+
integers, decimal = english.split(".")
|
23
|
+
integers ||= ""
|
25
24
|
|
26
|
-
thousands_separator = I18n.t(
|
27
|
-
integers.gsub(
|
25
|
+
thousands_separator = I18n.t("numbers.thousands_separator")
|
26
|
+
integers.gsub(",", thousands_separator)
|
28
27
|
|
29
28
|
return integers if decimal.nil?
|
30
29
|
|
31
|
-
decimal_separator = I18n.t(
|
30
|
+
decimal_separator = I18n.t("numbers.decimal_separator")
|
32
31
|
integers + decimal_separator + decimal
|
33
32
|
end
|
34
33
|
end
|
data/lib/m9t/pressure.rb
CHANGED
data/lib/m9t/speed.rb
CHANGED
data/lib/m9t/temperature.rb
CHANGED
data/lib/m9t/version.rb
CHANGED
data/m9t.gemspec
CHANGED
@@ -1,31 +1,30 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require 'm9t/version'
|
1
|
+
$LOAD_PATH.unshift(File.expand_path("../lib", __FILE__))
|
2
|
+
require "m9t/version"
|
4
3
|
|
5
4
|
gemspec = Gem::Specification.new do |s|
|
6
|
-
s.name =
|
5
|
+
s.name = "m9t"
|
7
6
|
s.platform = Gem::Platform::RUBY
|
8
7
|
s.version = M9t::VERSION::STRING
|
9
|
-
s.required_ruby_version =
|
8
|
+
s.required_ruby_version = ">= 2.4.0"
|
10
9
|
|
11
|
-
s.summary =
|
12
|
-
s.description =
|
10
|
+
s.summary = "Measurements and conversions library for Ruby"
|
11
|
+
s.description = "Classes for handling basic measurement units: distance, direction, speed, temperature and pressure"
|
13
12
|
s.license = "MIT"
|
14
13
|
|
15
|
-
s.homepage =
|
16
|
-
s.author =
|
17
|
-
s.email =
|
14
|
+
s.homepage = "https://github.com/joeyates/m9t"
|
15
|
+
s.author = "Joe Yates"
|
16
|
+
s.email = "joe.g.yates@gmail.com"
|
18
17
|
|
19
18
|
s.files = `git ls-files`.lines.map(&:chomp!)
|
20
19
|
s.test_files = `git ls-files spec`.lines.map(&:chomp!)
|
21
|
-
s.require_paths = [
|
20
|
+
s.require_paths = ["lib"]
|
22
21
|
|
23
|
-
s.rubyforge_project =
|
22
|
+
s.rubyforge_project = "nowarning"
|
24
23
|
|
25
|
-
s.add_dependency
|
26
|
-
s.add_dependency
|
24
|
+
s.add_dependency "rake"
|
25
|
+
s.add_dependency "i18n", ">= 0.3.5"
|
27
26
|
|
28
|
-
s.add_development_dependency
|
29
|
-
s.add_development_dependency
|
30
|
-
s.add_development_dependency
|
27
|
+
s.add_development_dependency "codeclimate-test-reporter", "~> 0.4.8"
|
28
|
+
s.add_development_dependency "rspec", ">= 3.0.0"
|
29
|
+
s.add_development_dependency "simplecov" if RUBY_PLATFORM != "java"
|
31
30
|
end
|
data/spec/base_spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'm9t/base'
|
1
|
+
require "m9t/base"
|
4
2
|
|
5
3
|
class SomeMeasurement
|
6
4
|
DEFAULT_OPTIONS = {
|
@@ -19,62 +17,62 @@ end
|
|
19
17
|
class SomeDerivedMeasurement < SomeMeasurement; end
|
20
18
|
|
21
19
|
describe M9t::Base do
|
22
|
-
describe
|
23
|
-
it
|
20
|
+
describe ".respond_to?" do
|
21
|
+
it "is true for conversion between known units" do
|
24
22
|
expect(SomeMeasurement.respond_to?(:foos_to_bars)).to be_truthy
|
25
23
|
end
|
26
24
|
|
27
|
-
it
|
25
|
+
it "is false for unknown units" do
|
28
26
|
expect(SomeMeasurement.respond_to?(:bazs_to_bars)).to be_falsey
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
|
-
describe
|
33
|
-
it
|
30
|
+
describe ".method_missing" do
|
31
|
+
it "handles conversion between known units" do
|
34
32
|
expect(SomeMeasurement.foos_to_bars(3.0)).to be_a(Float)
|
35
33
|
end
|
36
34
|
|
37
|
-
it
|
35
|
+
it "fails for unknown units" do
|
38
36
|
expect {
|
39
37
|
SomeMeasurement.bazs_to_bars(3.0)
|
40
38
|
}.to raise_error(NoMethodError)
|
41
39
|
end
|
42
40
|
end
|
43
41
|
|
44
|
-
describe
|
42
|
+
describe "#respond_to?" do
|
45
43
|
subject { SomeMeasurement.new(3.0) }
|
46
44
|
|
47
|
-
it
|
45
|
+
it "is true for conversion to known units" do
|
48
46
|
expect(subject.respond_to?(:to_bars)).to be_truthy
|
49
47
|
end
|
50
48
|
|
51
|
-
it
|
49
|
+
it "is false for unknown units" do
|
52
50
|
expect(subject.respond_to?(:to_bazs)).to be_falsey
|
53
51
|
end
|
54
52
|
|
55
|
-
context
|
56
|
-
it
|
53
|
+
context "for unrecognized calls" do
|
54
|
+
it "calls super" do
|
57
55
|
expect(subject.respond_to?(:ciao)).to be_falsey
|
58
56
|
end
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
|
-
describe
|
60
|
+
describe "#method_missing" do
|
63
61
|
subject { SomeMeasurement.new(3.0) }
|
64
62
|
|
65
|
-
it
|
63
|
+
it "handles conversion to known units" do
|
66
64
|
expect(subject.to_bars).to be_a(Float)
|
67
65
|
end
|
68
66
|
|
69
|
-
it
|
67
|
+
it "fails for unknown units" do
|
70
68
|
expect {
|
71
69
|
subject.to_bazs(3.0)
|
72
70
|
}.to raise_error(NoMethodError)
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
76
|
-
describe
|
77
|
-
it
|
74
|
+
describe "derived class" do
|
75
|
+
it "inherits options" do
|
78
76
|
expect(SomeDerivedMeasurement.options).to eq(SomeMeasurement.options)
|
79
77
|
end
|
80
78
|
end
|
data/spec/direction_spec.rb
CHANGED
@@ -1,64 +1,74 @@
|
|
1
|
-
|
2
|
-
require 'spec_helper'
|
3
|
-
require 'm9t/direction'
|
1
|
+
require "m9t/direction"
|
4
2
|
|
5
3
|
describe M9t::Direction do
|
6
4
|
before do
|
7
5
|
I18n.locale = :en
|
8
6
|
end
|
9
7
|
|
10
|
-
describe
|
8
|
+
describe ".measurement_name" do
|
11
9
|
it "is 'direction'" do
|
12
|
-
expect(M9t::Direction.measurement_name).to eq(
|
10
|
+
expect(M9t::Direction.measurement_name).to eq("direction")
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
16
|
-
describe
|
17
|
-
it
|
14
|
+
describe ".options" do
|
15
|
+
it "is set" do
|
18
16
|
expect(M9t::Direction.options).not_to be_nil
|
19
17
|
end
|
20
18
|
|
21
|
-
context
|
22
|
-
it
|
19
|
+
context "abbreviated" do
|
20
|
+
it "is false" do
|
23
21
|
expect(M9t::Direction.options[:abbreviated]).to be_falsey
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
27
|
-
context
|
28
|
-
it
|
25
|
+
context "units" do
|
26
|
+
it "is degrees" do
|
29
27
|
expect(M9t::Direction.options[:units]).to eq(:degrees)
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|
33
31
|
|
34
|
-
describe
|
35
|
-
it
|
32
|
+
describe ".normalize" do
|
33
|
+
it "reduces number greater than 360" do
|
36
34
|
expect(M9t::Direction.normalize(725)).to eq(5)
|
37
35
|
end
|
38
36
|
|
39
|
-
it
|
37
|
+
it "reduces 360" do
|
38
|
+
expect(M9t::Direction.normalize(360)).to eq(0)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "increases numbers less than zero" do
|
40
42
|
expect(M9t::Direction.normalize(-355)).to eq(5)
|
41
43
|
end
|
44
|
+
|
45
|
+
it "handles values with decimals" do
|
46
|
+
expect(M9t::Direction.normalize(360.5)).to eq(0.5)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "handles large values" do
|
50
|
+
M9t::Direction.normalize(1000000000)
|
51
|
+
end
|
42
52
|
end
|
43
53
|
|
44
|
-
context
|
45
|
-
describe
|
46
|
-
it
|
54
|
+
context "conversion class methods" do
|
55
|
+
describe ".degrees_to_degrees" do
|
56
|
+
it "returns the identity" do
|
47
57
|
expect(M9t::Direction.degrees_to_degrees(45)).to eq(45)
|
48
58
|
end
|
49
59
|
end
|
50
60
|
|
51
|
-
describe
|
61
|
+
describe ".degrees_to_compass" do
|
52
62
|
before do
|
53
63
|
I18n.locale = :en
|
54
64
|
end
|
55
65
|
|
56
|
-
context
|
66
|
+
context "exact" do
|
57
67
|
[
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
68
|
+
"N", "NNE", "NE", "ENE",
|
69
|
+
"E", "ESE", "SE", "SSE",
|
70
|
+
"S", "SSW", "SW", "WSW",
|
71
|
+
"W", "WNW", "NW", "NNW"
|
62
72
|
].each.with_index do |result, i|
|
63
73
|
it "recognizes #{result}" do
|
64
74
|
expect(M9t::Direction.degrees_to_compass(i * 22.5)).to eq(result)
|
@@ -66,121 +76,120 @@ describe M9t::Direction do
|
|
66
76
|
end
|
67
77
|
end
|
68
78
|
|
69
|
-
context
|
70
|
-
specify
|
71
|
-
expect(M9t::Direction.degrees_to_compass(42)).to eq(
|
79
|
+
context "rounding" do
|
80
|
+
specify "up" do
|
81
|
+
expect(M9t::Direction.degrees_to_compass(42)).to eq("NE")
|
72
82
|
end
|
73
83
|
|
74
|
-
specify
|
75
|
-
expect(M9t::Direction.degrees_to_compass(93)).to eq(
|
84
|
+
specify "down" do
|
85
|
+
expect(M9t::Direction.degrees_to_compass(93)).to eq("E")
|
76
86
|
end
|
77
87
|
end
|
78
88
|
|
79
|
-
context
|
89
|
+
context "i18n" do
|
80
90
|
before do
|
81
91
|
I18n.locale = :it
|
82
92
|
end
|
83
93
|
|
84
|
-
it
|
85
|
-
expect(M9t::Direction.degrees_to_compass(270)).to eq(
|
94
|
+
it "translates" do
|
95
|
+
expect(M9t::Direction.degrees_to_compass(270)).to eq("O")
|
86
96
|
end
|
87
97
|
end
|
88
98
|
end
|
89
99
|
|
90
|
-
describe
|
91
|
-
it
|
92
|
-
expect(M9t::Direction.compass_to_degrees(
|
100
|
+
describe "compass_to_degrees" do
|
101
|
+
it "converts correctly" do
|
102
|
+
expect(M9t::Direction.compass_to_degrees("WSW")).to eq(247.5)
|
93
103
|
end
|
94
104
|
end
|
95
105
|
end
|
96
106
|
|
97
|
-
describe
|
98
|
-
context
|
99
|
-
it
|
100
|
-
expect(M9t::Direction.new(
|
107
|
+
describe ".new" do
|
108
|
+
context "strings" do
|
109
|
+
it "works" do
|
110
|
+
expect(M9t::Direction.new("35").value).to eq(35)
|
101
111
|
end
|
102
112
|
|
103
|
-
it
|
104
|
-
expect(M9t::Direction.new(
|
113
|
+
it "handles leading zeroes" do
|
114
|
+
expect(M9t::Direction.new("010").value).to eq(10)
|
105
115
|
end
|
106
116
|
end
|
107
117
|
end
|
108
118
|
|
109
|
-
describe
|
110
|
-
it
|
111
|
-
expect(M9t::Direction.compass(
|
119
|
+
describe ".compass" do
|
120
|
+
it "converts cardinals" do
|
121
|
+
expect(M9t::Direction.compass("N").value).to eq(0)
|
112
122
|
end
|
113
123
|
|
114
|
-
it
|
115
|
-
expect(M9t::Direction.compass(
|
124
|
+
it "handles 16ths" do
|
125
|
+
expect(M9t::Direction.compass("WSW").value).to eq(247.5)
|
116
126
|
end
|
117
127
|
end
|
118
128
|
|
119
|
-
describe
|
129
|
+
describe "#value" do
|
120
130
|
let(:degrees) { M9t::Direction.new(45) }
|
121
131
|
|
122
|
-
it
|
132
|
+
it "returns the supplied value" do
|
123
133
|
expect(degrees.value).to eq(45)
|
124
134
|
end
|
125
135
|
end
|
126
136
|
|
127
|
-
describe
|
128
|
-
context
|
129
|
-
context
|
137
|
+
describe "#to_s" do
|
138
|
+
context "not abbreviated" do
|
139
|
+
context "singular" do
|
130
140
|
subject { M9t::Direction.new(1) }
|
131
141
|
|
132
|
-
it
|
133
|
-
expect(subject.to_s).to eq(
|
142
|
+
it "returns the full unit name" do
|
143
|
+
expect(subject.to_s).to eq("1 degree")
|
134
144
|
end
|
135
145
|
|
136
|
-
it
|
146
|
+
it "translates" do
|
137
147
|
I18n.locale = :it
|
138
|
-
expect(subject.to_s).to eq(
|
148
|
+
expect(subject.to_s).to eq("1 grado")
|
139
149
|
end
|
140
150
|
end
|
141
151
|
|
142
|
-
context
|
152
|
+
context "plural" do
|
143
153
|
subject { M9t::Direction.new(135) }
|
144
154
|
|
145
|
-
it
|
146
|
-
expect(subject.to_s).to eq(
|
155
|
+
it "returns the full unit name" do
|
156
|
+
expect(subject.to_s).to eq("135 degrees")
|
147
157
|
end
|
148
158
|
|
149
|
-
it
|
159
|
+
it "translates" do
|
150
160
|
I18n.locale = :it
|
151
|
-
expect(subject.to_s).to eq(
|
161
|
+
expect(subject.to_s).to eq("135 gradi")
|
152
162
|
end
|
153
163
|
end
|
154
164
|
end
|
155
165
|
|
156
|
-
context
|
166
|
+
context "abbreviated" do
|
157
167
|
subject { M9t::Direction.new(135) }
|
158
168
|
|
159
|
-
it
|
160
|
-
expect(subject.to_s(abbreviated: true)).to eq(
|
169
|
+
it "uses the symbol" do
|
170
|
+
expect(subject.to_s(abbreviated: true)).to eq("135°")
|
161
171
|
end
|
162
172
|
end
|
163
173
|
|
164
|
-
context
|
174
|
+
context "compass units" do
|
165
175
|
subject { M9t::Direction.new(225) }
|
166
176
|
|
167
|
-
it
|
168
|
-
expect(subject.to_s(units: :compass)).to eq(
|
177
|
+
it "works" do
|
178
|
+
expect(subject.to_s(units: :compass)).to eq("SW")
|
169
179
|
end
|
170
180
|
|
171
|
-
it
|
181
|
+
it "translates" do
|
172
182
|
I18n.locale = :it
|
173
|
-
expect(subject.to_s(units: :compass)).to eq(
|
183
|
+
expect(subject.to_s(units: :compass)).to eq("SO")
|
174
184
|
end
|
175
185
|
end
|
176
186
|
end
|
177
187
|
|
178
|
-
describe
|
188
|
+
describe "#to_compass" do
|
179
189
|
subject { M9t::Direction.new(0) }
|
180
190
|
|
181
|
-
it
|
182
|
-
expect(subject.to_compass).to eq(
|
191
|
+
it "is correct" do
|
192
|
+
expect(subject.to_compass).to eq("N")
|
183
193
|
end
|
184
194
|
end
|
185
195
|
end
|
186
|
-
|