megli_common_helper 1.0.5 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ext/string.rb +13 -0
- data/lib/helpers/common_helper.rb +15 -0
- data/lib/megli_helper.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5633127fbe2f8ab61424e02fb3ae2202998216d8
|
4
|
+
data.tar.gz: 7f2357713a86361061a2129a6c00f5126c612905
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2724732d56e514f0d09d9419ff6b453528c254690fe556081b10f36ead17d785ff2b27897a0ed17ae2f30ffdca544d30fdd5d035e4178bf225b05e761596ddb
|
7
|
+
data.tar.gz: 76170b8a253a75d81bf9863421193309554b8c8d0de63d6f8cccce6f3d89fc7c1fd3862e612e8573d0be847802d64b2ccd509173c3eca72a26b5cf18984373b8
|
data/lib/ext/string.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class String
|
2
|
+
# Convert a string in snake case
|
3
|
+
# Example: "testTest" => "test_test"
|
4
|
+
# @return [String]
|
5
|
+
def underscore
|
6
|
+
gsub(/::/, '/')
|
7
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
|
8
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2')
|
9
|
+
.tr('-', '_')
|
10
|
+
.tr(' ', '_')
|
11
|
+
.downcase
|
12
|
+
end
|
13
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'timeout'
|
3
|
+
require_relative '../ext/string'
|
3
4
|
|
4
5
|
module MegliHelper
|
5
6
|
class CommonHelper
|
@@ -39,6 +40,20 @@ module MegliHelper
|
|
39
40
|
new_decimal
|
40
41
|
end
|
41
42
|
|
43
|
+
# Transform keys of hash or array of hashes in snake case
|
44
|
+
# @param hash_object [Array/Hash] object that will be formatted
|
45
|
+
# @return [Array/Hash] keys converted in snake case
|
46
|
+
def self.transform_hash_keys_in_snake_case(hash_object)
|
47
|
+
case hash_object
|
48
|
+
when Array
|
49
|
+
hash_object.map { |v| transform_hash_keys_in_snake_case(v) }
|
50
|
+
when Hash
|
51
|
+
Hash[hash_object.map { |k, v| [k.to_s.underscore, transform_hash_keys_in_snake_case(v)] }]
|
52
|
+
else
|
53
|
+
hash_object
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
42
57
|
# Check if the JSON passed is valid or not
|
43
58
|
# @param json [String] json to be verified
|
44
59
|
# @return [Boolean] is valid or not
|
data/lib/megli_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: megli_common_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eduardo Gomes Heinen
|
@@ -16,6 +16,7 @@ executables: []
|
|
16
16
|
extensions: []
|
17
17
|
extra_rdoc_files: []
|
18
18
|
files:
|
19
|
+
- lib/ext/string.rb
|
19
20
|
- lib/helpers/assert_helper.rb
|
20
21
|
- lib/helpers/common_helper.rb
|
21
22
|
- lib/helpers/time_helper.rb
|