rb-net_http-client 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/core/utilities.rb +29 -12
- data/lib/version.rb +1 -1
- data/spec/unit/core/utilities_spec.rb +60 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 05f76d705b77e966b3451fc8407c38f495e5acc4eab044fd5d7b020d54cadb30
|
4
|
+
data.tar.gz: cd0804d36dca24700e707c41191d40e2007b2ed51a632454d77b39b8a951d5b1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f5e0bd2fa634025f34c4670adf9166bf619ff8bdf5562ee936494870cbc0597e2297b834af7ebc8e7bdd29a8c68aa6792d7c41fdef7c077507e77aee0abe61c
|
7
|
+
data.tar.gz: 30134abad71bc61d14ae90ae64d4ef67448fab235c113f4b7f44a4c39576e66256f0165f595cc68a946bdc6d377161c8113df6ffbf3484f62c32ef335c149c75
|
data/lib/core/utilities.rb
CHANGED
@@ -59,11 +59,13 @@ module NetHTTP
|
|
59
59
|
|
60
60
|
port = uri.to_s.scan(%r{:([0-9]+)}).flatten[0].to_s
|
61
61
|
return URI("http://#{uri.to_s.gsub("#{scheme}://", '')}") if port == '80'
|
62
|
+
|
62
63
|
URI("https://#{uri.to_s.gsub("#{scheme}://", '')}")
|
63
64
|
end
|
64
65
|
|
65
66
|
# CamelCase to snake_case
|
66
67
|
def self.camel_2_snake(key, type = nil)
|
68
|
+
key_class = key.class.to_s.downcase
|
67
69
|
new_key = key.to_s
|
68
70
|
.tr('::', '/')
|
69
71
|
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
@@ -71,29 +73,44 @@ module NetHTTP
|
|
71
73
|
.tr('-', '_')
|
72
74
|
.downcase
|
73
75
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
# return the newly formatted key without modifying the type
|
77
|
+
if type.nil?
|
78
|
+
case key_class
|
79
|
+
when 'string'
|
80
|
+
return new_key.to_s
|
81
|
+
when 'symbol'
|
82
|
+
return new_key.to_sym
|
83
|
+
end
|
79
84
|
end
|
80
85
|
|
81
|
-
|
86
|
+
# return the newly formatted key in type format requested
|
87
|
+
return new_key.to_s if type.to_s.downcase == 'string'
|
88
|
+
return new_key.to_sym if type.to_s.downcase == 'symbol'
|
89
|
+
|
90
|
+
nil
|
82
91
|
end
|
83
92
|
|
84
93
|
# snake_case to CamelCase
|
85
94
|
def self.snake_2_camel(key, type = nil)
|
95
|
+
key_class = key.class.to_s.downcase
|
86
96
|
new_key = key.to_s.split('_')
|
87
97
|
new_key = new_key[0].downcase + new_key[1..-1].map(&:capitalize).join('')
|
88
98
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
99
|
+
# return the newly formatted key without modifying the type
|
100
|
+
if type.nil?
|
101
|
+
case key_class
|
102
|
+
when 'string'
|
103
|
+
return new_key.to_s
|
104
|
+
when 'symbol'
|
105
|
+
return new_key.to_sym
|
106
|
+
end
|
94
107
|
end
|
95
108
|
|
96
|
-
|
109
|
+
# return the newly formatted key in type format requested
|
110
|
+
return new_key.to_s if type.to_s.downcase == 'string'
|
111
|
+
return new_key.to_sym if type.to_s.downcase == 'symbol'
|
112
|
+
|
113
|
+
nil
|
97
114
|
end
|
98
115
|
|
99
116
|
# convert hash / array / nested object keys to either snake_case or CamelCase
|
data/lib/version.rb
CHANGED
@@ -227,4 +227,64 @@ describe 'NetHTTP::Core::Utilities' do
|
|
227
227
|
valid_html = NetHTTP::Core::Utilities.valid_html?(html_doc)
|
228
228
|
expect(valid_html).to eq(false)
|
229
229
|
end
|
230
|
+
|
231
|
+
it 'returns snake case string key when camel case string key and type nil is provided' do
|
232
|
+
new_key = NetHTTP::Core::Utilities.camel_2_snake('stringKey')
|
233
|
+
expect(new_key).to eq('string_key')
|
234
|
+
end
|
235
|
+
|
236
|
+
it 'returns camel case string key when snake case string key and type nil is provided' do
|
237
|
+
new_key = NetHTTP::Core::Utilities.snake_2_camel('string_key')
|
238
|
+
expect(new_key).to eq('stringKey')
|
239
|
+
end
|
240
|
+
|
241
|
+
it 'returns snake case symbol key when camel case symbol key and type nil is provided' do
|
242
|
+
new_key = NetHTTP::Core::Utilities.camel_2_snake(:symbolKey)
|
243
|
+
expect(new_key).to eq(:symbol_key)
|
244
|
+
end
|
245
|
+
|
246
|
+
it 'returns camel case symbol key when snake case symbol key and type nil is provided' do
|
247
|
+
new_key = NetHTTP::Core::Utilities.snake_2_camel(:symbol_key)
|
248
|
+
expect(new_key).to eq(:symbolKey)
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'returns snake case symbol key when camel case string key and type symbol is provided' do
|
252
|
+
new_key = NetHTTP::Core::Utilities.camel_2_snake('stringKey', 'symbol')
|
253
|
+
expect(new_key).to eq(:string_key)
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'returns camel case symbol key when snake case string key and type symbol is provided' do
|
257
|
+
new_key = NetHTTP::Core::Utilities.snake_2_camel('string_key', 'symbol')
|
258
|
+
expect(new_key).to eq(:stringKey)
|
259
|
+
end
|
260
|
+
|
261
|
+
it 'returns snake case string key when camel case symbol key and type string is provided' do
|
262
|
+
new_key = NetHTTP::Core::Utilities.camel_2_snake(:symbolKey, 'string')
|
263
|
+
expect(new_key).to eq('symbol_key')
|
264
|
+
end
|
265
|
+
|
266
|
+
it 'returns camel case string key when snake case symbol key and type string is provided' do
|
267
|
+
new_key = NetHTTP::Core::Utilities.snake_2_camel(:symbol_key, 'string')
|
268
|
+
expect(new_key).to eq('symbolKey')
|
269
|
+
end
|
270
|
+
|
271
|
+
it 'returns snake case string key when camel case string key and type string is provided' do
|
272
|
+
new_key = NetHTTP::Core::Utilities.camel_2_snake('stringKey', 'string')
|
273
|
+
expect(new_key).to eq('string_key')
|
274
|
+
end
|
275
|
+
|
276
|
+
it 'returns camel case string key when snake case string key and type string is provided' do
|
277
|
+
new_key = NetHTTP::Core::Utilities.snake_2_camel('string_key', 'string')
|
278
|
+
expect(new_key).to eq('stringKey')
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'returns snake case symbol key when camel case symbol key and type symbol is provided' do
|
282
|
+
new_key = NetHTTP::Core::Utilities.camel_2_snake(:symbolKey, 'symbol')
|
283
|
+
expect(new_key).to eq(:symbol_key)
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'returns camel case symbol key when snake case symbol key and type symbol is provided' do
|
287
|
+
new_key = NetHTTP::Core::Utilities.snake_2_camel(:symbol_key, 'symbol')
|
288
|
+
expect(new_key).to eq(:symbolKey)
|
289
|
+
end
|
230
290
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rb-net_http-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Bostian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-03-
|
11
|
+
date: 2019-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|