active_object 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/.coveralls.yml +1 -0
- data/.gitignore +14 -0
- data/.rspec +4 -0
- data/.travis.yml +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +1361 -0
- data/Rakefile +1 -0
- data/active_object.gemspec +25 -0
- data/lib/active_object.rb +9 -0
- data/lib/active_object/array.rb +118 -0
- data/lib/active_object/enumerable.rb +172 -0
- data/lib/active_object/hash.rb +203 -0
- data/lib/active_object/integer.rb +7 -0
- data/lib/active_object/numeric.rb +523 -0
- data/lib/active_object/object.rb +41 -0
- data/lib/active_object/string.rb +311 -0
- data/lib/active_object/time.rb +150 -0
- data/lib/active_object/version.rb +3 -0
- data/spec/lib/array_spec.rb +125 -0
- data/spec/lib/enumerable_spec.rb +326 -0
- data/spec/lib/hash_spec.rb +191 -0
- data/spec/lib/integer_spec.rb +11 -0
- data/spec/lib/numeric_spec.rb +604 -0
- data/spec/lib/object_spec.rb +85 -0
- data/spec/lib/string_spec.rb +459 -0
- data/spec/lib/time_spec.rb +455 -0
- data/spec/spec_helper.rb +4 -0
- metadata +137 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
|
5
|
+
describe "#assert_valid_keys" do
|
6
|
+
it "to be {}" do
|
7
|
+
expect({}.assert_valid_keys(:foo)).to eq({})
|
8
|
+
end
|
9
|
+
|
10
|
+
it "to be { foo: 'bar' }" do
|
11
|
+
expect({ foo: "bar" }.assert_valid_keys(:foo)).to eq({ foo: "bar" })
|
12
|
+
end
|
13
|
+
|
14
|
+
it "to raise error" do
|
15
|
+
expect { { foo: "bar", baz: "boz" }.assert_valid_keys(:foo) }.to raise_error
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe "#compact(!)" do
|
20
|
+
it "to be nil" do
|
21
|
+
expect({}.compact!).to eq(nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "to be {}" do
|
25
|
+
expect({}.compact).to eq({})
|
26
|
+
expect({ foo: nil }.compact).to eq({})
|
27
|
+
expect({ foo: nil }.compact!).to eq({})
|
28
|
+
end
|
29
|
+
|
30
|
+
it "to be { foo: 'bar', baz: false, boo: nil }" do
|
31
|
+
expect({ foo: "bar", baz: false, boo: nil }.compact).to eq({ foo: "bar", baz: false })
|
32
|
+
expect({ foo: "bar", baz: false, boo: nil }.compact!).to eq({ foo: "bar", baz: false })
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "#deep_dup(!)" do
|
37
|
+
it "to be { a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } }" do
|
38
|
+
h1 = { a: true, b: { c: [1, 2, 3] } }
|
39
|
+
h2 = { a: false, b: { x: [3, 4, 5] } }
|
40
|
+
|
41
|
+
expect(h1.deep_merge(h2)).to eq({ a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } })
|
42
|
+
expect(h1.deep_merge!(h2)).to eq({ a: false, b: { c: [1, 2, 3], x: [3, 4, 5] } })
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#except(!)" do
|
47
|
+
it "to be {}" do
|
48
|
+
expect({}.except(:foo)).to eq({})
|
49
|
+
expect({}.except!(:foo)).to eq({})
|
50
|
+
end
|
51
|
+
|
52
|
+
it "to be { :foo => 1 }" do
|
53
|
+
expect({ foo: 1, baz: 2, bar: 3 }.except(:baz, :bar)).to eq({ foo: 1 })
|
54
|
+
expect({ foo: 1, baz: 2, bar: 3 }.except!(:baz, :bar)).to eq({ foo: 1 })
|
55
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.except(:baz, :bar)).to eq({ :foo => 1 })
|
56
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.except!(:baz, :bar)).to eq({ :foo => 1 })
|
57
|
+
end
|
58
|
+
|
59
|
+
it "to be { :baz => 2, :bar => 3 }" do
|
60
|
+
expect({ foo: 1, baz: 2, bar: 3 }.except(:foo)).to eq({ baz: 2, bar: 3 })
|
61
|
+
expect({ foo: 1, baz: 2, bar: 3 }.except!(:foo)).to eq({ baz: 2, bar: 3 })
|
62
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.except(:foo)).to eq({ :baz => 2, :bar => 3 })
|
63
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.except!(:foo)).to eq({ :baz => 2, :bar => 3 })
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#nillify" do
|
68
|
+
it "to be {a: 1, b: 'test', c: nil, d: nil, e: nil, f: nil}" do
|
69
|
+
expect({ a: 1, b: "test", c: nil, d: false, e: "", f: " " }.nillify).to eq({a: 1, b: 'test', c: nil, d: nil, e: nil, f: nil})
|
70
|
+
expect({ a: 1, b: "test", c: nil, d: false, e: "", f: " " }.nillify!).to eq({a: 1, b: 'test', c: nil, d: nil, e: nil, f: nil})
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#only(!)" do
|
75
|
+
it "to be {}" do
|
76
|
+
expect({}.only(:foo)).to eq({})
|
77
|
+
expect({}.only!(:foo)).to eq({})
|
78
|
+
end
|
79
|
+
|
80
|
+
it "to be { :foo => 1 }" do
|
81
|
+
expect({ foo: 1, baz: 2, bar: 3 }.only(:foo)).to eq({ foo: 1 })
|
82
|
+
expect({ foo: 1, baz: 2, bar: 3 }.only!(:foo)).to eq({ foo: 1 })
|
83
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.only(:foo)).to eq({ :foo => 1 })
|
84
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.only!(:foo)).to eq({ :foo => 1 })
|
85
|
+
end
|
86
|
+
|
87
|
+
it "to be { :baz => 2, :bar => 3 }" do
|
88
|
+
expect({ foo: 1, baz: 2, bar: 3 }.only(:baz, :bar)).to eq({ baz: 2, bar: 3 })
|
89
|
+
expect({ foo: 1, baz: 2, bar: 3 }.only!(:baz, :bar)).to eq({ baz: 2, bar: 3 })
|
90
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.only(:baz, :bar)).to eq({ :baz => 2, :bar => 3 })
|
91
|
+
expect({ :foo => 1, :baz => 2, :bar => 3 }.only!(:baz, :bar)).to eq({ :baz => 2, :bar => 3 })
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe "#rename_keys(!)" do
|
96
|
+
it "to be [:baz, :bar]" do
|
97
|
+
expect({ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar).keys).to eq([:baz, :bar])
|
98
|
+
expect({ foo: 'foo', baz: 'baz' }.rename_keys!(foo: :bar).keys).to eq([:baz, :bar])
|
99
|
+
end
|
100
|
+
|
101
|
+
it "to be [:foo, 'tick']" do
|
102
|
+
expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys('baz' => 'tick').keys).to eq([:foo, 'tick'])
|
103
|
+
expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys!('baz' => 'tick').keys).to eq([:foo, 'tick'])
|
104
|
+
end
|
105
|
+
|
106
|
+
it "to be [:bar, :tick]" do
|
107
|
+
expect({ foo: 'foo', baz: 'baz' }.rename_keys(foo: :bar, baz: :tick).keys).to eq([:bar, :tick])
|
108
|
+
expect({ foo: 'foo', baz: 'baz' }.rename_keys!(foo: :bar, baz: :tick).keys).to eq([:bar, :tick])
|
109
|
+
end
|
110
|
+
|
111
|
+
it "to be [:bar, 'tick']" do
|
112
|
+
expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys(foo: :bar, 'baz' => 'tick').keys).to eq([:bar, 'tick'])
|
113
|
+
expect({ foo: 'foo', 'baz' => 'baz' }.rename_keys!(foo: :bar, 'baz' => 'tick').keys).to eq([:bar, 'tick'])
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "#reverse_merge(!)" do
|
118
|
+
it "to be { foo: 'bar' }" do
|
119
|
+
expect({}.reverse_merge(foo: "bar")).to eq({ foo: "bar" })
|
120
|
+
expect({}.reverse_merge!(foo: "bar")).to eq({ foo: "bar" })
|
121
|
+
end
|
122
|
+
|
123
|
+
it "to be { foo: 'bar', baz: 'boo', boo: 'bam' }" do
|
124
|
+
expect({ foo: "bar" }.reverse_merge(baz: "boo", boo: "bam")).to eq({ foo: "bar", baz: "boo", boo: "bam" })
|
125
|
+
expect({ foo: "bar" }.reverse_merge!(baz: "boo", boo: "bam")).to eq({ foo: "bar", baz: "boo", boo: "bam" })
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#slice(!)" do
|
130
|
+
it "to be { a: 1, b: 2 }" do
|
131
|
+
expect({ a: 1, b: 2, c: 3, d: 4 }.slice(:a, :b)).to eq({ a: 1, b: 2 })
|
132
|
+
end
|
133
|
+
|
134
|
+
it "to be { a: 3, b: 4 }" do
|
135
|
+
expect({ a: 1, b: 2, c: 3, d: 4 }.slice!(:a, :b)).to eq({ c: 3, d: 4 })
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#stringify_keys(!)" do
|
140
|
+
it "to be { 'foo' => 'foo', 'bar' => 'bar' }" do
|
141
|
+
expect({ foo: 'foo', 'bar' => 'bar' }.stringify_keys).to eq({ 'foo' => 'foo', 'bar' => 'bar' })
|
142
|
+
expect({ foo: 'foo', 'bar' => 'bar' }.stringify_keys!).to eq({ 'foo' => 'foo', 'bar' => 'bar' })
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
describe "#strip(!)" do
|
147
|
+
it "to be nil" do
|
148
|
+
expect({}.strip!).to eq(nil)
|
149
|
+
end
|
150
|
+
|
151
|
+
it "to be {}" do
|
152
|
+
expect({}.strip).to eq({})
|
153
|
+
expect({ foo: nil, baz: false, boo: '', faz: ' ' }.strip).to eq({})
|
154
|
+
expect({ foo: nil, baz: false, boo: '', faz: ' ' }.strip!).to eq({})
|
155
|
+
end
|
156
|
+
|
157
|
+
it "to be { foo: 'bar', baz: false, boo: nil }" do
|
158
|
+
expect({ foo: "bar", baz: false, boo: nil, boz: '', faz: ' ' }.strip).to eq({ foo: "bar" })
|
159
|
+
expect({ foo: "bar", baz: false, boo: nil, boz: '', faz: ' ' }.strip!).to eq({ foo: "bar" })
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
describe "#symbolize_keys(!)" do
|
164
|
+
it "to be { foo: 'foo', bar: 'bar' }" do
|
165
|
+
expect({ foo: 'foo', 'bar' => 'bar' }.symbolize_keys).to eq({ foo: 'foo', bar: 'bar' })
|
166
|
+
expect({ foo: 'foo', 'bar' => 'bar' }.symbolize_keys!).to eq({ foo: 'foo', bar: 'bar' })
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "#symbolize_and_underscore_keys(!)" do
|
171
|
+
it "to be { foo_bar: 'example', baz_bar: 'string' }" do
|
172
|
+
expect({ 'foo Bar' => 'example', bazBar: 'string' }.symbolize_and_underscore_keys).to eq({ foo_bar: 'example', baz_bar: 'string' })
|
173
|
+
expect({ 'foo Bar' => 'example', bazBar: 'string' }.symbolize_and_underscore_keys!).to eq({ foo_bar: 'example', baz_bar: 'string' })
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe "#transform_keys(!)" do
|
178
|
+
it "to be { 'FOO' => 'foo', 'BAZ' => 'bar' }" do
|
179
|
+
expect({ foo: 'bar', baz: 'boo' }.transform_keys { |k| k.to_s.upcase }).to eq({ "FOO" => 'bar', "BAZ" => 'boo' })
|
180
|
+
expect({ foo: 'bar', baz: 'boo' }.transform_keys! { |k| k.to_s.upcase }).to eq({ "FOO" => 'bar', "BAZ" => 'boo' })
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
describe "#transform_values(!)" do
|
185
|
+
it "to be { foo: 'BAR', baz: 'BOO' }" do
|
186
|
+
expect({ foo: 'bar', baz: 'boo' }.transform_values { |v| v.to_s.upcase }).to eq({ foo: 'BAR', baz: 'BOO' })
|
187
|
+
expect({ foo: 'bar', baz: 'boo' }.transform_values! { |v| v.to_s.upcase }).to eq({ foo: 'BAR', baz: 'BOO' })
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
@@ -0,0 +1,604 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Numeric do
|
4
|
+
|
5
|
+
describe "#add" do
|
6
|
+
it "to be 6" do
|
7
|
+
expect(4.add(2)).to eq(6)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#byte(s)" do
|
12
|
+
it "to be 3" do
|
13
|
+
expect(3.byte).to eq(3)
|
14
|
+
expect(3.bytes).to eq(3)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#centigram(s)" do
|
19
|
+
it "to be 0.03" do
|
20
|
+
expect(3.centigram).to eq(0.03)
|
21
|
+
expect(3.centigram).to eq(0.03)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe "#centimeter(s)" do
|
26
|
+
it "to be 0.03" do
|
27
|
+
expect(3.centimeter).to eq(0.03)
|
28
|
+
expect(3.centimeters).to eq(0.03)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#century(s)" do
|
33
|
+
it "to be 259200" do
|
34
|
+
expect(3.century).to eq(9467280000.0)
|
35
|
+
expect(3.centuries).to eq(9467280000.0)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#decade(s)" do
|
40
|
+
it "to be 259200" do
|
41
|
+
expect(3.decade).to eq(946728000.0)
|
42
|
+
expect(3.decades).to eq(946728000.0)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe "#decagram(s)" do
|
47
|
+
it "to be 30" do
|
48
|
+
expect(3.decagram).to eq(30)
|
49
|
+
expect(3.decagrams).to eq(30)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#decameter(s)" do
|
54
|
+
it "to be 30" do
|
55
|
+
expect(3.decameter).to eq(30)
|
56
|
+
expect(3.decameters).to eq(30)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "#decigrams(s)" do
|
61
|
+
it "to be 0.3" do
|
62
|
+
expect(3.decigram).to eq(0.30000000000000004)
|
63
|
+
expect(3.decigrams).to eq(0.30000000000000004)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe "#decimeter(s)" do
|
68
|
+
it "to be 0.3" do
|
69
|
+
expect(3.decimeter).to eq(0.30000000000000004)
|
70
|
+
expect(3.decimeters).to eq(0.30000000000000004)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#day(s)" do
|
75
|
+
it "to be 259200" do
|
76
|
+
expect(3.day).to eq(259200)
|
77
|
+
expect(3.days).to eq(259200)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "#divide" do
|
82
|
+
it "to be 2" do
|
83
|
+
expect(4.divide(2)).to eq(2)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe "#exabyte(s)" do
|
88
|
+
it "to be 3458764513820540928" do
|
89
|
+
expect(3.exabyte).to eq(3458764513820540928)
|
90
|
+
expect(3.exabytes).to eq(3458764513820540928)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#feet(s)" do
|
95
|
+
it "to be 36" do
|
96
|
+
expect(3.foot).to eq(36)
|
97
|
+
expect(3.feet).to eq(36)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe "#gigabyte(s)" do
|
102
|
+
it "to be 3221225472" do
|
103
|
+
expect(3.gigabyte).to eq(3221225472)
|
104
|
+
expect(3.gigabytes).to eq(3221225472)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#gram(s)" do
|
109
|
+
it "to be 300" do
|
110
|
+
expect(3.gram).to eq(3)
|
111
|
+
expect(3.grams).to eq(3)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#hectogram(s)" do
|
116
|
+
it "to be 300" do
|
117
|
+
expect(3.hectogram).to eq(300)
|
118
|
+
expect(3.hectograms).to eq(300)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe "#hectometer(s)" do
|
123
|
+
it "to be 300" do
|
124
|
+
expect(3.hectometer).to eq(300)
|
125
|
+
expect(3.hectometers).to eq(300)
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
describe "#hour(s)" do
|
130
|
+
it "to be 10800" do
|
131
|
+
expect(3.hour).to eq(10800)
|
132
|
+
expect(3.hours).to eq(10800)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#inch(s)" do
|
137
|
+
it "to be 3" do
|
138
|
+
expect(3.inch).to eq(3)
|
139
|
+
expect(3.inches).to eq(3)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe "#kilobyte(s)" do
|
144
|
+
it "to be 3072" do
|
145
|
+
expect(3.kilobyte).to eq(3072)
|
146
|
+
expect(3.kilobytes).to eq(3072)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#kilograms(s)" do
|
151
|
+
it "to be 3000" do
|
152
|
+
expect(3.kilogram).to eq(3000)
|
153
|
+
expect(3.kilograms).to eq(3000)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "#kilometer(s)" do
|
158
|
+
it "to be 3000" do
|
159
|
+
expect(3.kilometer).to eq(3000)
|
160
|
+
expect(3.kilometers).to eq(3000)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
describe "#metric_ton(s)" do
|
165
|
+
it "to be 3000000" do
|
166
|
+
expect(3.metric_ton).to eq(3000000)
|
167
|
+
expect(3.metric_tons).to eq(3000000)
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
describe "#megabyte(s)" do
|
172
|
+
it "to be 3145728" do
|
173
|
+
expect(3.megabyte).to eq(3145728)
|
174
|
+
expect(3.megabytes).to eq(3145728)
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
describe "#meter(s)" do
|
179
|
+
it "to be 3" do
|
180
|
+
expect(3.meter).to eq(3)
|
181
|
+
expect(3.meters).to eq(3)
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe "#mile(s)" do
|
186
|
+
it "to be 36" do
|
187
|
+
expect(3.mile).to eq(190080)
|
188
|
+
expect(3.miles).to eq(190080)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
describe "#millennium(s)" do
|
193
|
+
it "to be 94672800000.0" do
|
194
|
+
expect(3.millennium).to eq(94672800000.0)
|
195
|
+
expect(3.millenniums).to eq(94672800000.0)
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
describe "#milligrams(s)" do
|
200
|
+
it "to be 0.003" do
|
201
|
+
expect(3.milligram).to eq(0.003)
|
202
|
+
expect(3.milligrams).to eq(0.003)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe "#millimeter(s)" do
|
207
|
+
it "to be 0.003" do
|
208
|
+
expect(3.millimeter).to eq(0.003)
|
209
|
+
expect(3.millimeters).to eq(0.003)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
213
|
+
describe "#minute(s)" do
|
214
|
+
it "to be 180" do
|
215
|
+
expect(3.minute).to eq(180)
|
216
|
+
expect(3.minutes).to eq(180)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe "#multiply" do
|
221
|
+
it "to be 8" do
|
222
|
+
expect(4.multiply(2)).to eq(8)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
describe "#multiple_of?" do
|
227
|
+
it "to be true" do
|
228
|
+
expect(9.multiple_of?(3)).to eq(true)
|
229
|
+
expect(12.multiple_of?(3)).to eq(true)
|
230
|
+
end
|
231
|
+
|
232
|
+
it "to be false" do
|
233
|
+
expect(10.multiple_of?(3)).to eq(false)
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
describe "#nautical_mile(s)" do
|
238
|
+
it "to be 218740.26239999998" do
|
239
|
+
expect(3.nautical_mile).to eq(218740.26239999998)
|
240
|
+
expect(3.nautical_miles).to eq(218740.26239999998)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
describe "#negative?" do
|
245
|
+
it "to be true" do
|
246
|
+
expect(-1.negative?).to eq(true)
|
247
|
+
end
|
248
|
+
|
249
|
+
it "to be false" do
|
250
|
+
expect(1.negative?).to eq(false)
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "#ordinal" do
|
255
|
+
it "to be st" do
|
256
|
+
expect(1.ordinal).to eq("st")
|
257
|
+
end
|
258
|
+
|
259
|
+
it "to be nd" do
|
260
|
+
expect(2.ordinal).to eq("nd")
|
261
|
+
end
|
262
|
+
|
263
|
+
it "to be rd" do
|
264
|
+
expect(3.ordinal).to eq("rd")
|
265
|
+
end
|
266
|
+
|
267
|
+
it "to be th" do
|
268
|
+
expect(11.ordinal).to eq("th")
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
describe "#ordinalize" do
|
273
|
+
it "to be st" do
|
274
|
+
expect(1.ordinalize).to eq("1st")
|
275
|
+
end
|
276
|
+
|
277
|
+
it "to be nd" do
|
278
|
+
expect(2.ordinalize).to eq("2nd")
|
279
|
+
end
|
280
|
+
|
281
|
+
it "to be rd" do
|
282
|
+
expect(3.ordinalize).to eq("3rd")
|
283
|
+
end
|
284
|
+
|
285
|
+
it "to be th" do
|
286
|
+
expect(11.ordinalize).to eq("11th")
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
describe "#ounce(s)" do
|
291
|
+
it "to be 3" do
|
292
|
+
expect(3.ounce).to eq(3)
|
293
|
+
expect(3.ounces).to eq(3)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
describe "#pad" do
|
298
|
+
it "to be 003" do
|
299
|
+
expect(3.pad).to eq("003")
|
300
|
+
end
|
301
|
+
|
302
|
+
it "to be 113" do
|
303
|
+
expect(3.pad(pad_number: 1)).to eq("113")
|
304
|
+
end
|
305
|
+
|
306
|
+
it "to be 0003" do
|
307
|
+
expect(3.pad(precision: 4)).to eq("0003")
|
308
|
+
end
|
309
|
+
|
310
|
+
it "to be 003.5" do
|
311
|
+
expect(3.5.pad(precision: 5)).to eq("003.5")
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
describe "#pad_precision" do
|
316
|
+
it "to be 3" do
|
317
|
+
expect(3.pad_precision).to eq("3.00")
|
318
|
+
end
|
319
|
+
|
320
|
+
it "to be 3.50" do
|
321
|
+
expect(3.5.pad_precision).to eq("3.50")
|
322
|
+
end
|
323
|
+
|
324
|
+
it "to be 3.11" do
|
325
|
+
expect(3.pad_precision(pad_number: 1)).to eq("3.11")
|
326
|
+
end
|
327
|
+
|
328
|
+
it "to be 3.000" do
|
329
|
+
expect(3.pad_precision(precision: 3)).to eq("3.000")
|
330
|
+
end
|
331
|
+
|
332
|
+
it "to be 3,00" do
|
333
|
+
expect(3.pad_precision(separator: ",")).to eq("3,00")
|
334
|
+
end
|
335
|
+
end
|
336
|
+
|
337
|
+
describe "#petabyte(s)" do
|
338
|
+
it "to be 3377699720527872" do
|
339
|
+
expect(3.petabyte).to eq(3377699720527872)
|
340
|
+
expect(3.petabytes).to eq(3377699720527872)
|
341
|
+
end
|
342
|
+
end
|
343
|
+
|
344
|
+
describe "#positive?" do
|
345
|
+
it "to be true" do
|
346
|
+
expect(1.positive?).to eq(true)
|
347
|
+
end
|
348
|
+
|
349
|
+
it "to be false" do
|
350
|
+
expect(-1.positive?).to eq(false)
|
351
|
+
end
|
352
|
+
end
|
353
|
+
|
354
|
+
describe "#pound(s)" do
|
355
|
+
it "to be 48" do
|
356
|
+
expect(3.pound).to eq(48)
|
357
|
+
expect(3.pounds).to eq(48)
|
358
|
+
end
|
359
|
+
end
|
360
|
+
|
361
|
+
describe "#power" do
|
362
|
+
it "to be 16" do
|
363
|
+
expect(4.power(2)).to eq(16)
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
describe "#root" do
|
368
|
+
it "to be 2" do
|
369
|
+
expect(4.root(2)).to eq(2)
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
describe "#second(s)" do
|
374
|
+
it "to be 3" do
|
375
|
+
expect(3.second).to eq(3)
|
376
|
+
expect(3.seconds).to eq(3)
|
377
|
+
end
|
378
|
+
end
|
379
|
+
|
380
|
+
describe "#stone(s)" do
|
381
|
+
it "to be 672" do
|
382
|
+
expect(3.stone).to eq(672)
|
383
|
+
expect(3.stones).to eq(672)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
|
387
|
+
describe "#subtract" do
|
388
|
+
it "to be 2" do
|
389
|
+
expect(4.subtract(2)).to eq(2)
|
390
|
+
end
|
391
|
+
end
|
392
|
+
|
393
|
+
describe "#terabyte(s)" do
|
394
|
+
it "to be 3298534883328" do
|
395
|
+
expect(3.terabyte).to eq(3298534883328)
|
396
|
+
expect(3.terabytes).to eq(3298534883328)
|
397
|
+
end
|
398
|
+
end
|
399
|
+
|
400
|
+
describe "#to_byte" do
|
401
|
+
it "to be 1" do
|
402
|
+
expect(1024.to_byte(:kilobyte, :megabyte)).to eq(1)
|
403
|
+
end
|
404
|
+
|
405
|
+
it "to be 5" do
|
406
|
+
expect(5120.to_byte(:kilobyte, :megabyte)).to eq(5)
|
407
|
+
end
|
408
|
+
|
409
|
+
it "to be 1024" do
|
410
|
+
expect(1024.to_byte(:kilobyte, :kilobyte)).to eq(1024)
|
411
|
+
expect(1.to_byte(:megabyte, :kilobyte)).to eq(1024)
|
412
|
+
end
|
413
|
+
|
414
|
+
it "to be 1048576" do
|
415
|
+
expect(1.to_byte(:gigabyte, :kilobyte)).to eq(1048576)
|
416
|
+
end
|
417
|
+
|
418
|
+
it "to be 0.078125" do
|
419
|
+
expect(80.to_byte(:megabyte, :gigabyte)).to eq(0.078125)
|
420
|
+
end
|
421
|
+
|
422
|
+
it "to raise error" do
|
423
|
+
expect { 1.to_byte }.to raise_error
|
424
|
+
expect { 1.to_byte(:bad, :kilobyte) }.to raise_error
|
425
|
+
expect { 1.to_byte(:kilobyte, :bad) }.to raise_error
|
426
|
+
expect { 1.to_byte(:bad, :bad) }.to raise_error
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
describe "#to_length" do
|
431
|
+
it "to be 1" do
|
432
|
+
expect(1.to_length(:millimeter, :millimeter)).to eq(1)
|
433
|
+
expect(1.to_length(:inches, :inches)).to eq(1)
|
434
|
+
expect(10.to_length(:millimeters, :centimeters)).to eq(1)
|
435
|
+
expect(12.to_length(:inches, :feet)).to eq(1)
|
436
|
+
end
|
437
|
+
|
438
|
+
it "to be 10" do
|
439
|
+
expect(1.to_length(:centimeters, :millimeters)).to eq(10)
|
440
|
+
end
|
441
|
+
|
442
|
+
it "to be 12" do
|
443
|
+
expect(1.to_length(:feet, :inches)).to eq(12)
|
444
|
+
end
|
445
|
+
|
446
|
+
it "to be 30.479999999999997" do
|
447
|
+
expect(1.to_length(:feet, :centimeters)).to eq(30.479999999999997)
|
448
|
+
end
|
449
|
+
|
450
|
+
it "to be 1093.6138888888888" do
|
451
|
+
expect(1.to_length(:kilometer, :yard)).to eq(1093.6138888888888)
|
452
|
+
end
|
453
|
+
|
454
|
+
it "to be 6076.118399999999" do
|
455
|
+
expect(1.to_length(:nautical_miles, :feet)).to eq(6076.118399999999)
|
456
|
+
end
|
457
|
+
|
458
|
+
it "to raise error" do
|
459
|
+
expect { 1.to_length }.to raise_error
|
460
|
+
expect { 1.to_length(:bad, :meters) }.to raise_error
|
461
|
+
expect { 1.to_length(:meters, :bad) }.to raise_error
|
462
|
+
expect { 1.to_length(:bad, :bad) }.to raise_error
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
describe "#to_mass" do
|
467
|
+
it "to be 1" do
|
468
|
+
expect(1.to_mass(:milligram, :milligram)).to eq(1)
|
469
|
+
expect(1.to_mass(:ounces, :ounces)).to eq(1)
|
470
|
+
expect(10.to_mass(:milligram, :centigram)).to eq(1)
|
471
|
+
expect(16.to_mass(:ounces, :pounds)).to eq(1)
|
472
|
+
end
|
473
|
+
|
474
|
+
it "to be 1.360776" do
|
475
|
+
expect(3.to_mass(:pound, :kilogram)).to eq(1.360776)
|
476
|
+
end
|
477
|
+
|
478
|
+
it "to be 1.1023125" do
|
479
|
+
expect(1.to_mass(:metric_ton, :ton)).to eq(1.1023125)
|
480
|
+
end
|
481
|
+
|
482
|
+
it "to be 2.204625" do
|
483
|
+
expect(1.to_mass(:kilograms, :pounds)).to eq(2.204625)
|
484
|
+
end
|
485
|
+
|
486
|
+
it "to be 10" do
|
487
|
+
expect(1.to_mass(:centigrams, :milligrams)).to eq(10)
|
488
|
+
end
|
489
|
+
|
490
|
+
it "to be 16" do
|
491
|
+
expect(1.to_mass(:pounds, :ounces)).to eq(16)
|
492
|
+
end
|
493
|
+
|
494
|
+
it "to be 64000" do
|
495
|
+
expect(2.to_mass(:tons, :pounds)).to eq(4000)
|
496
|
+
end
|
497
|
+
|
498
|
+
it "to raise error" do
|
499
|
+
expect { 1.to_mass }.to raise_error
|
500
|
+
expect { 1.to_mass(:bad, :pound) }.to raise_error
|
501
|
+
expect { 1.to_mass(:pound, :bad) }.to raise_error
|
502
|
+
expect { 1.to_mass(:bad, :bad) }.to raise_error
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
describe "#to_nearest_value" do
|
507
|
+
it "to be 6" do
|
508
|
+
expect(5.to_nearest_value([1, 3, 6, 9])).to eq(6)
|
509
|
+
end
|
510
|
+
|
511
|
+
it "to be 3.6" do
|
512
|
+
expect(3.5.to_nearest_value([3.0, 3.3, 3.6, 3.9])).to eq(3.6)
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
describe "#to_temperature" do
|
517
|
+
it "to be 212" do
|
518
|
+
expect(100.to_temperature(:celsius, :fahrenheit)).to eq(212)
|
519
|
+
end
|
520
|
+
|
521
|
+
it "to be 100" do
|
522
|
+
expect(100.to_temperature(:celsius, :celsius)).to eq(100)
|
523
|
+
expect(212.to_temperature(:fahrenheit, :celsius)).to eq(100)
|
524
|
+
end
|
525
|
+
|
526
|
+
it "to be 373.15" do
|
527
|
+
expect(100.to_temperature(:celsius, :kelvin)).to eq(373.15)
|
528
|
+
expect(212.to_temperature(:fahrenheit, :kelvin)).to eq(373.15)
|
529
|
+
end
|
530
|
+
|
531
|
+
it "to be -173.15" do
|
532
|
+
expect(100.to_temperature(:kelvin, :celsius)).to eq(-173.14999999999998)
|
533
|
+
end
|
534
|
+
|
535
|
+
it "to be -279.67" do
|
536
|
+
expect(100.to_temperature(:kelvin, :fahrenheit)).to eq(-279.66999999999996)
|
537
|
+
end
|
538
|
+
|
539
|
+
it "to raise error" do
|
540
|
+
expect { 1.to_temperature }.to raise_error
|
541
|
+
expect { 1.to_temperature(:bad, :kelvin) }.to raise_error
|
542
|
+
expect { 1.to_temperature(:kelvin, :bad) }.to raise_error
|
543
|
+
expect { 1.to_temperature(:bad, :bad) }.to raise_error
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
describe "#to_time" do
|
548
|
+
it "to be 2" do
|
549
|
+
expect(120.to_time(:seconds, :minutes)).to eq(2)
|
550
|
+
end
|
551
|
+
|
552
|
+
it "to be 40" do
|
553
|
+
expect(2400.to_time(:minutes, :hours)).to eq(40)
|
554
|
+
end
|
555
|
+
|
556
|
+
it "to be 3" do
|
557
|
+
expect(72.to_time(:hours, :days)).to eq(3)
|
558
|
+
end
|
559
|
+
|
560
|
+
it "to be 5" do
|
561
|
+
expect(1825.to_time(:days, :years)).to eq(4.996577686516085)
|
562
|
+
end
|
563
|
+
|
564
|
+
it "to be 172800" do
|
565
|
+
expect(2.to_time(:days, :seconds)).to eq(172800)
|
566
|
+
end
|
567
|
+
|
568
|
+
it "to raise error" do
|
569
|
+
expect { 1.to_time }.to raise_error
|
570
|
+
expect { 1.to_time(:bad, :days) }.to raise_error
|
571
|
+
expect { 1.to_time(:days, :bad) }.to raise_error
|
572
|
+
expect { 1.to_time(:bad, :bad) }.to raise_error
|
573
|
+
end
|
574
|
+
end
|
575
|
+
|
576
|
+
describe "#ton(s)" do
|
577
|
+
it "to be 96000" do
|
578
|
+
expect(3.ton).to eq(96000)
|
579
|
+
expect(3.tons).to eq(96000)
|
580
|
+
end
|
581
|
+
end
|
582
|
+
|
583
|
+
describe "#week(s)" do
|
584
|
+
it "to be 1814400" do
|
585
|
+
expect(3.week).to eq(1814400)
|
586
|
+
expect(3.weeks).to eq(1814400)
|
587
|
+
end
|
588
|
+
end
|
589
|
+
|
590
|
+
describe "#yard(s)" do
|
591
|
+
it "to be 36" do
|
592
|
+
expect(3.yard).to eq(108)
|
593
|
+
expect(3.yards).to eq(108)
|
594
|
+
end
|
595
|
+
end
|
596
|
+
|
597
|
+
describe "#year(s)" do
|
598
|
+
it "to be 94672800.0" do
|
599
|
+
expect(3.year).to eq(94672800.0)
|
600
|
+
expect(3.years).to eq(94672800.0)
|
601
|
+
end
|
602
|
+
end
|
603
|
+
|
604
|
+
end
|