utilise 0.5.0.pre.42 → 0.5.0.pre.47
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 +8 -8
- data/lib/utilise/array.rb +1 -1
- data/lib/utilise/augment/bool.rb +1 -1
- data/lib/utilise/augment/hash.rb +41 -0
- data/lib/utilise/augment/modify.rb +4 -2
- data/lib/utilise/fixnum.rb +1 -1
- data/lib/utilise/hash.rb +3 -1
- data/lib/utilise/hashie.rb +1 -1
- data/lib/utilise/object.rb +1 -1
- data/lib/utilise/string.rb +2 -2
- data/lib/utilise/symbol.rb +3 -1
- data/lib/utilise/time.rb +1 -1
- data/spec/spec_helper.rb +0 -1
- data/spec/utilise/hash_spec.rb +201 -0
- data/spec/utilise/{augment/hashie_spec.rb → hashie_spec.rb} +1 -1
- data/spec/utilise/{augment/string_spec.rb → string_spec.rb} +4 -4
- metadata +18 -17
- data/spec/utilise/augment/hash_spec.rb +0 -73
- /data/spec/utilise/{augment/array_spec.rb → array_spec.rb} +0 -0
- /data/spec/utilise/{augment/fixnum_spec.rb → fixnum_spec.rb} +0 -0
- /data/spec/utilise/{augment/object_spec.rb → object_spec.rb} +0 -0
- /data/spec/utilise/{augment/symbol_spec.rb → symbol_spec.rb} +0 -0
- /data/spec/utilise/{augment/time_spec.rb → time_spec.rb} +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ODI4ZGIyYWRkZDlmMjQyOTRmODNiMDIxYTMxMTkyYjA3ZDcyZTgyMA==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NjQ3YzA0NjgxNDkyOGQ2ZDUxZTJiNDQzMzIwZDBmYWYyMDllYzY0Yw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OGU3MzFkMGYwZDQxYzVhZGEwNmJmNjBjZTVhZjVhNjBkMDQxY2QxMTQ5Zjhk
|
10
|
+
NjY5YmNhY2Q3Y2I1MWQwOThlMGU2ZWI3OTk3NTY3NmIyNGMzOWRhMzI3ODZi
|
11
|
+
MzIzYzRmNDY2ZjgyZGI4NjRjMWIwYmJlMzVjNDQ2NWZkNWZlYmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MTk1YTliZDM2YmQ5ZTJmYTczMWFjMWQ0OTkzZTA5NGI2ZTE0NjY3MmFhMDlm
|
14
|
+
MmIwMjIyZTgwMTk4Y2RlY2QwYWRiNGI1ZDdhN2E1YmMyMDZkMmMyMmRmN2Y4
|
15
|
+
ODNjZGMyNmUzZDIyZmJmN2VkZjdjNTJhYTRjYTM4MjgwY2Y4Mzg=
|
data/lib/utilise/array.rb
CHANGED
data/lib/utilise/augment/bool.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'utilise/string'
|
2
|
+
|
3
|
+
module Utilise
|
4
|
+
module Augment
|
5
|
+
# Extends a hash to modify keys
|
6
|
+
module Hash
|
7
|
+
# Transforms all keys to snake case
|
8
|
+
def snake_keys
|
9
|
+
transform_keys(self) { |key| key.snake }
|
10
|
+
end
|
11
|
+
|
12
|
+
# Transforms all keys to camel case
|
13
|
+
def camel_keys
|
14
|
+
transform_keys(self) { |key| key.camel }
|
15
|
+
end
|
16
|
+
|
17
|
+
# Transforms all keys to space case
|
18
|
+
def space_keys
|
19
|
+
transform_keys(self) { |key| key.space }
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# Deep transform keys
|
25
|
+
# An awesome piece of code from rails
|
26
|
+
# apidock.com/rails/v4.2.1/Hash/_deep_transform_keys_in_object%21
|
27
|
+
def transform_keys(object, &block)
|
28
|
+
case object
|
29
|
+
when Hash
|
30
|
+
object.each_with_object({}) do |(key, value), result|
|
31
|
+
result[yield(key)] = transform_keys(value, &block)
|
32
|
+
end
|
33
|
+
when Array
|
34
|
+
object.map { |e| transform_keys(e, &block) }
|
35
|
+
else
|
36
|
+
object
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -4,7 +4,8 @@ module Utilise
|
|
4
4
|
module Modify
|
5
5
|
# Return a string in modified camel case
|
6
6
|
def camel
|
7
|
-
split_up
|
7
|
+
array = split_up
|
8
|
+
array.first + array[1..-1].map(&:capitalize).join('')
|
8
9
|
end
|
9
10
|
|
10
11
|
# Return a string in snake case
|
@@ -21,7 +22,8 @@ module Utilise
|
|
21
22
|
|
22
23
|
# Splits up the current string into an array and normalises it
|
23
24
|
def split_up
|
24
|
-
|
25
|
+
regex = /(?<=[a-z])(?=[A-Z])|(?<=[A-Z])(?=[A-Z][a-z])|(?=_)|(?= )/
|
26
|
+
arr = to_s.split(regex)
|
25
27
|
arr.map!(&:downcase)
|
26
28
|
arr.map!(&:strip)
|
27
29
|
arr.map { |s| s.delete('_') }
|
data/lib/utilise/fixnum.rb
CHANGED
data/lib/utilise/hash.rb
CHANGED
data/lib/utilise/hashie.rb
CHANGED
data/lib/utilise/object.rb
CHANGED
data/lib/utilise/string.rb
CHANGED
data/lib/utilise/symbol.rb
CHANGED
data/lib/utilise/time.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,201 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Hash do
|
4
|
+
describe '#to_bool' do
|
5
|
+
it 'returns hash with true when key value is 1' do
|
6
|
+
expect({ 'key' => 1 }.to_bool).to eql('key' => true)
|
7
|
+
end
|
8
|
+
|
9
|
+
it 'returns hash with false when key value is 0' do
|
10
|
+
expect({ 'key' => 0 }.to_bool).to eql('key' => false)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'returns original hash when key value is not 0 or 1' do
|
14
|
+
expect({ 'key' => 2 }.to_bool).to eql('key' => 2)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns hash with true when key value is 'yes'" do
|
18
|
+
expect({ 'key' => 'yes' }.to_bool).to eql('key' => true)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "returns hash with false when key value is 'no'" do
|
22
|
+
expect({ 'key' => 'no' }.to_bool).to eql('key' => false)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns hash with true when key value is 'true'" do
|
26
|
+
expect({ 'key' => 'true' }.to_bool).to eql('key' => true)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "returns hash with false when key value is 'false'" do
|
30
|
+
expect({ 'key' => 'false' }.to_bool).to eql('key' => false)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "returns original hash when key value is not 'yes', 'no', 'true or 'false'" do
|
34
|
+
expect({ 'key' => 'value' }.to_bool).to eql('key' => 'value')
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'returns hash with true when key value is :t' do
|
38
|
+
expect({ 'key' => :t }.to_bool).to eql('key' => true)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'returns hash with false when key value is :f' do
|
42
|
+
expect({ 'key' => :f }.to_bool).to eql('key' => false)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'returns hash with true when key value is :t' do
|
46
|
+
expect({ 'key' => :yes }.to_bool).to eql('key' => true)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'returns hash with false when key value is :f' do
|
50
|
+
expect({ 'key' => :no }.to_bool).to eql('key' => false)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns hash with true when key value is :true' do
|
54
|
+
expect({ 'key' => :true }.to_bool).to eql('key' => true)
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'returns hash with false when key value is :false' do
|
58
|
+
expect({ 'key' => :false }.to_bool).to eql('key' => false)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'returns original hash when key value is not :t or :n' do
|
62
|
+
expect({ 'key' => :symbol }.to_bool).to eql('key' => :symbol)
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'returns correct hash with multiple values' do
|
66
|
+
expect({ 'key0' => 1, 'key1' => 0, 'key2' => 'yes', 'key3' => 'false', 'key4' => :t, 'key4' => :f, 'key5' => :true, 'key6' => :false }.to_bool).to eql('key0' => true, 'key1' => false, 'key2' => true, 'key3' => false, 'key4' => true, 'key4' => false, 'key5' => true, 'key6' => false)
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'returns correct multi-level hash with multiple values' do
|
70
|
+
expect({ 'key0' => { 'key1' => 1 }, 'key2' => { 'key3' => 0 } }.to_bool).to eql('key0' => { 'key1' => true }, 'key2' => { 'key3' => false })
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#snake_keys' do
|
75
|
+
let(:hash) { { oneKey: 'aString', two_key: ['a_string'], 'red key' => { blueKey: 'testing 123' } } }
|
76
|
+
|
77
|
+
it 'coverts all keys to snake case' do
|
78
|
+
new_hash = hash.snake_keys
|
79
|
+
expect(new_hash.key?('one_key')).to be_truthy
|
80
|
+
expect(new_hash.key?('two_key')).to be_truthy
|
81
|
+
expect(new_hash.key?('red_key')).to be_truthy
|
82
|
+
expect(new_hash['red_key'].key?('blue_key')).to be_truthy
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'does not transfer the old keys' do
|
86
|
+
new_hash = hash.snake_keys
|
87
|
+
expect(new_hash.key?(:oneKey)).to be_falsey
|
88
|
+
expect(new_hash.key?(:two_key)).to be_falsey
|
89
|
+
expect(new_hash.key?('red key')).to be_falsey
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'does not convert the values' do
|
93
|
+
new_hash = hash.snake_keys
|
94
|
+
expect(new_hash['one_key']).to eql('aString')
|
95
|
+
expect(new_hash['two_key']).to eql(['a_string'])
|
96
|
+
expect(new_hash['red_key']).to be_a(Hash)
|
97
|
+
expect(new_hash['red_key']['blue_key']).to eql('testing 123')
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'does not modify the original hash' do
|
101
|
+
old_hash = hash
|
102
|
+
old_hash.snake_keys
|
103
|
+
|
104
|
+
expect(old_hash.key?(:oneKey)).to be_truthy
|
105
|
+
expect(old_hash.key?(:two_key)).to be_truthy
|
106
|
+
expect(old_hash.key?('red key')).to be_truthy
|
107
|
+
expect(old_hash['red key'].key?(:blueKey)).to be_truthy
|
108
|
+
|
109
|
+
expect(old_hash[:oneKey]).to eql('aString')
|
110
|
+
expect(old_hash[:two_key]).to eql(['a_string'])
|
111
|
+
expect(old_hash['red key']).to be_a(Hash)
|
112
|
+
expect(old_hash['red key'][:blueKey]).to eql('testing 123')
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe '#camel_keys' do
|
117
|
+
let(:hash) { { oneKey: 'aString', two_key: ['a_string'], 'red key' => { blueKey: 'testing 123' } } }
|
118
|
+
|
119
|
+
it 'coverts all keys to camel case' do
|
120
|
+
new_hash = hash.camel_keys
|
121
|
+
expect(new_hash.key?('oneKey')).to be_truthy
|
122
|
+
expect(new_hash.key?('twoKey')).to be_truthy
|
123
|
+
expect(new_hash.key?('redKey')).to be_truthy
|
124
|
+
expect(new_hash['redKey'].key?('blueKey')).to be_truthy
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'does not transfer the old keys' do
|
128
|
+
new_hash = hash.camel_keys
|
129
|
+
expect(new_hash.key?(:oneKey)).to be_falsey
|
130
|
+
expect(new_hash.key?(:two_key)).to be_falsey
|
131
|
+
expect(new_hash.key?('red key')).to be_falsey
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'does not convert the values' do
|
135
|
+
new_hash = hash.camel_keys
|
136
|
+
|
137
|
+
expect(new_hash['oneKey']).to eql('aString')
|
138
|
+
expect(new_hash['twoKey']).to eql(['a_string'])
|
139
|
+
expect(new_hash['redKey']).to be_a(Hash)
|
140
|
+
expect(new_hash['redKey']['blueKey']).to eql('testing 123')
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'does not modify the original hash' do
|
144
|
+
old_hash = hash
|
145
|
+
old_hash.camel_keys
|
146
|
+
|
147
|
+
expect(old_hash.key?(:oneKey)).to be_truthy
|
148
|
+
expect(old_hash.key?(:two_key)).to be_truthy
|
149
|
+
expect(old_hash.key?('red key')).to be_truthy
|
150
|
+
expect(old_hash['red key'].key?(:blueKey)).to be_truthy
|
151
|
+
|
152
|
+
expect(old_hash[:oneKey]).to eql('aString')
|
153
|
+
expect(old_hash[:two_key]).to eql(['a_string'])
|
154
|
+
expect(old_hash['red key']).to be_a(Hash)
|
155
|
+
expect(old_hash['red key'][:blueKey]).to eql('testing 123')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
describe '#space_keys' do
|
160
|
+
let(:hash) { { oneKey: 'aString', two_key: ['a_string'], 'red key' => { blueKey: 'testing 123' } } }
|
161
|
+
|
162
|
+
it 'coverts all keys to space case' do
|
163
|
+
new_hash = hash.space_keys
|
164
|
+
expect(new_hash.key?('one key')).to be_truthy
|
165
|
+
expect(new_hash.key?('two key')).to be_truthy
|
166
|
+
expect(new_hash.key?('red key')).to be_truthy
|
167
|
+
expect(new_hash['red key'].key?('blue key')).to be_truthy
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'does not transfer the old keys' do
|
171
|
+
new_hash = hash.space_keys
|
172
|
+
expect(new_hash.key?(:oneKey)).to be_falsey
|
173
|
+
expect(new_hash.key?(:two_key)).to be_falsey
|
174
|
+
expect(new_hash['red key'].key?(:blueKey)).to be_falsey
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'does not convert the values' do
|
178
|
+
new_hash = hash.space_keys
|
179
|
+
|
180
|
+
expect(new_hash['one key']).to eql('aString')
|
181
|
+
expect(new_hash['two key']).to eql(['a_string'])
|
182
|
+
expect(new_hash['red key']).to be_a(Hash)
|
183
|
+
expect(new_hash['red key']['blue key']).to eql('testing 123')
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'does not modify the original hash' do
|
187
|
+
old_hash = hash
|
188
|
+
old_hash.space_keys
|
189
|
+
|
190
|
+
expect(old_hash.key?(:oneKey)).to be_truthy
|
191
|
+
expect(old_hash.key?(:two_key)).to be_truthy
|
192
|
+
expect(old_hash.key?('red key')).to be_truthy
|
193
|
+
expect(old_hash['red key'].key?(:blueKey)).to be_truthy
|
194
|
+
|
195
|
+
expect(old_hash[:oneKey]).to eql('aString')
|
196
|
+
expect(old_hash[:two_key]).to eql(['a_string'])
|
197
|
+
expect(old_hash['red key']).to be_a(Hash)
|
198
|
+
expect(old_hash['red key'][:blueKey]).to eql('testing 123')
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
@@ -9,7 +9,7 @@ describe Utilise::Augment::Crash::Bash do
|
|
9
9
|
|
10
10
|
context 'a bash with keys' do
|
11
11
|
before do
|
12
|
-
@hash = Hashie::Bash.new(a:1, b:{ c: 2, d: { e: 3, f: {} } })
|
12
|
+
@hash = Hashie::Bash.new(a: 1, b: { c: 2, d: { e: 3, f: {} } })
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'has first layer keys' do
|
@@ -45,19 +45,19 @@ describe String do
|
|
45
45
|
|
46
46
|
describe '#camel' do
|
47
47
|
it 'returns a camel case from camel case' do
|
48
|
-
expect('CamelCase'.camel).to eq '
|
48
|
+
expect('CamelCase'.camel).to eq 'camelCase'
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'returns a camel case from snake case' do
|
52
|
-
expect('camel_case'.camel).to eq '
|
52
|
+
expect('camel_case'.camel).to eq 'camelCase'
|
53
53
|
end
|
54
54
|
|
55
55
|
it 'returns a camel case from space case' do
|
56
|
-
expect('camel case'.camel).to eq '
|
56
|
+
expect('camel case'.camel).to eq 'camelCase'
|
57
57
|
end
|
58
58
|
|
59
59
|
it 'returns a camel case from complex camel case' do
|
60
|
-
expect('CamelONECase'.camel).to eq '
|
60
|
+
expect('CamelONECase'.camel).to eq 'camelOneCase'
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utilise
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.0.pre.
|
4
|
+
version: 0.5.0.pre.47
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ben Slaughter
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/utilise/array.rb
|
121
121
|
- lib/utilise/augment/bool.rb
|
122
122
|
- lib/utilise/augment/crash.rb
|
123
|
+
- lib/utilise/augment/hash.rb
|
123
124
|
- lib/utilise/augment/matchers.rb
|
124
125
|
- lib/utilise/augment/modify.rb
|
125
126
|
- lib/utilise/augment/time.rb
|
@@ -132,14 +133,14 @@ files:
|
|
132
133
|
- lib/utilise/time.rb
|
133
134
|
- lib/utilise/version.rb
|
134
135
|
- spec/spec_helper.rb
|
135
|
-
- spec/utilise/
|
136
|
-
- spec/utilise/
|
137
|
-
- spec/utilise/
|
138
|
-
- spec/utilise/
|
139
|
-
- spec/utilise/
|
140
|
-
- spec/utilise/
|
141
|
-
- spec/utilise/
|
142
|
-
- spec/utilise/
|
136
|
+
- spec/utilise/array_spec.rb
|
137
|
+
- spec/utilise/fixnum_spec.rb
|
138
|
+
- spec/utilise/hash_spec.rb
|
139
|
+
- spec/utilise/hashie_spec.rb
|
140
|
+
- spec/utilise/object_spec.rb
|
141
|
+
- spec/utilise/string_spec.rb
|
142
|
+
- spec/utilise/symbol_spec.rb
|
143
|
+
- spec/utilise/time_spec.rb
|
143
144
|
- spec/utilise/version_spec.rb
|
144
145
|
homepage: http://benslaughter.github.io/utilise/
|
145
146
|
licenses:
|
@@ -167,12 +168,12 @@ specification_version: 4
|
|
167
168
|
summary: Utilises a few extra methods
|
168
169
|
test_files:
|
169
170
|
- spec/utilise/version_spec.rb
|
170
|
-
- spec/utilise/
|
171
|
-
- spec/utilise/
|
172
|
-
- spec/utilise/
|
173
|
-
- spec/utilise/
|
174
|
-
- spec/utilise/
|
175
|
-
- spec/utilise/
|
176
|
-
- spec/utilise/
|
177
|
-
- spec/utilise/
|
171
|
+
- spec/utilise/time_spec.rb
|
172
|
+
- spec/utilise/symbol_spec.rb
|
173
|
+
- spec/utilise/string_spec.rb
|
174
|
+
- spec/utilise/object_spec.rb
|
175
|
+
- spec/utilise/hashie_spec.rb
|
176
|
+
- spec/utilise/hash_spec.rb
|
177
|
+
- spec/utilise/fixnum_spec.rb
|
178
|
+
- spec/utilise/array_spec.rb
|
178
179
|
- spec/spec_helper.rb
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Hash do
|
4
|
-
describe '#to_bool' do
|
5
|
-
it 'returns hash with true when key value is 1' do
|
6
|
-
expect({ 'key' => 1 }.to_bool).to eql('key' => true)
|
7
|
-
end
|
8
|
-
|
9
|
-
it 'returns hash with false when key value is 0' do
|
10
|
-
expect({ 'key' => 0 }.to_bool).to eql('key' => false)
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'returns original hash when key value is not 0 or 1' do
|
14
|
-
expect({ 'key' => 2 }.to_bool).to eql('key' => 2)
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns hash with true when key value is 'yes'" do
|
18
|
-
expect({ 'key' => 'yes' }.to_bool).to eql('key' => true)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns hash with false when key value is 'no'" do
|
22
|
-
expect({ 'key' => 'no' }.to_bool).to eql('key' => false)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns hash with true when key value is 'true'" do
|
26
|
-
expect({ 'key' => 'true' }.to_bool).to eql('key' => true)
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns hash with false when key value is 'false'" do
|
30
|
-
expect({ 'key' => 'false' }.to_bool).to eql('key' => false)
|
31
|
-
end
|
32
|
-
|
33
|
-
it "returns original hash when key value is not 'yes', 'no', 'true or 'false'" do
|
34
|
-
expect({ 'key' => 'value' }.to_bool).to eql('key' => 'value')
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'returns hash with true when key value is :t' do
|
38
|
-
expect({ 'key' => :t }.to_bool).to eql('key' => true)
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'returns hash with false when key value is :f' do
|
42
|
-
expect({ 'key' => :f }.to_bool).to eql('key' => false)
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'returns hash with true when key value is :t' do
|
46
|
-
expect({ 'key' => :yes }.to_bool).to eql('key' => true)
|
47
|
-
end
|
48
|
-
|
49
|
-
it 'returns hash with false when key value is :f' do
|
50
|
-
expect({ 'key' => :no }.to_bool).to eql('key' => false)
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'returns hash with true when key value is :true' do
|
54
|
-
expect({ 'key' => :true }.to_bool).to eql('key' => true)
|
55
|
-
end
|
56
|
-
|
57
|
-
it 'returns hash with false when key value is :false' do
|
58
|
-
expect({ 'key' => :false }.to_bool).to eql('key' => false)
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'returns original hash when key value is not :t or :n' do
|
62
|
-
expect({ 'key' => :symbol }.to_bool).to eql('key' => :symbol)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'returns correct hash with multiple values' do
|
66
|
-
expect({ 'key0' => 1, 'key1' => 0, 'key2' => 'yes', 'key3' => 'false', 'key4' => :t, 'key4' => :f, 'key5' => :true, 'key6' => :false }.to_bool).to eql('key0' => true, 'key1' => false, 'key2' => true, 'key3' => false, 'key4' => true, 'key4' => false, 'key5' => true, 'key6' => false)
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'returns correct multi-level hash with multiple values' do
|
70
|
-
expect({ 'key0' => { 'key1' => 1 }, 'key2' => { 'key3' => 0 } }.to_bool).to eql('key0' => { 'key1' => true }, 'key2' => { 'key3' => false })
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|