notation_converter 1.0.0 → 1.0.1
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 +4 -4
- data/lib/notation_converter.rb +23 -5
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f9b03e5bc60070028618a3fd89c8d2ce32e29f68
|
4
|
+
data.tar.gz: e9144568f17b70f659f9d98a9c1a493af9684e23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13bea81646c2960965ce9bffac34a769d6b9871c54e7e146af06973eb60f40bb54cf4f75e6bbf3f84f278fdd30c3d6bc1022d95a85b39e046239ad18a9311218
|
7
|
+
data.tar.gz: 0a9b7d5b9ad4325274944b625cdfc2a450814051b27132eb50bb994cb68f88ef80bca9d8eb6e3778b3508e0650100edc5903b47b0b1184d7c09ec8dbee5eaacd
|
data/lib/notation_converter.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# Class with static methods responsible for converting hashes between snake and camel case notations
|
1
2
|
class NotationConverter
|
2
3
|
|
3
4
|
def self.convert_input(input, &conversion_logic)
|
@@ -6,9 +7,7 @@ class NotationConverter
|
|
6
7
|
|
7
8
|
new_input = {}
|
8
9
|
|
9
|
-
if input.kind_of?
|
10
|
-
|
11
|
-
elsif input.kind_of? Hash
|
10
|
+
if input.kind_of? Hash
|
12
11
|
input.each_pair do |k,v|
|
13
12
|
new_k = conversion_logic.call(k)
|
14
13
|
new_input[new_k] = (convert_input v, &conversion_logic)
|
@@ -17,8 +16,6 @@ class NotationConverter
|
|
17
16
|
new_input = input.map do |elem|
|
18
17
|
convert_input elem, &conversion_logic
|
19
18
|
end
|
20
|
-
#elsif input.kind_of? Object
|
21
|
-
|
22
19
|
else
|
23
20
|
new_input = input
|
24
21
|
end
|
@@ -32,6 +29,12 @@ class NotationConverter
|
|
32
29
|
(to_symbol) ? k.to_sym : k
|
33
30
|
end
|
34
31
|
|
32
|
+
# Converts passed input to camelCase notation (lower or upper based on passed type param)
|
33
|
+
#
|
34
|
+
# @param input [Hash|Array] input in snake_notation
|
35
|
+
# @param type [Symbol] the format type, `:lower` or `:upper` (default ':lower')
|
36
|
+
# @param to_symbol [Boolean] default false (defines if returned keys will be symbols or strings)
|
37
|
+
# @return [Hash|Array] input converted into the camelCase notation
|
35
38
|
def self.to_camel(input, type = :lower, to_symbol = false)
|
36
39
|
if type == :upper
|
37
40
|
to_upper_camel input, to_symbol
|
@@ -40,6 +43,11 @@ class NotationConverter
|
|
40
43
|
end
|
41
44
|
end
|
42
45
|
|
46
|
+
# Converts passed input to (Upper) CamelCase notation
|
47
|
+
#
|
48
|
+
# @param input [Hash|Array] input in snake_notation
|
49
|
+
# @param to_symbol [Boolean] default false (defines if returned keys will be symbols or strings)
|
50
|
+
# @return [Hash|Array] input converted into the (Upper) CamelCase notation
|
43
51
|
def self.to_upper_camel(input, to_symbol = false)
|
44
52
|
|
45
53
|
conversion_logic = lambda do |k|
|
@@ -50,6 +58,11 @@ class NotationConverter
|
|
50
58
|
|
51
59
|
end
|
52
60
|
|
61
|
+
# Converts passed input to (lower) camelCase notation
|
62
|
+
#
|
63
|
+
# @param input [Hash|Array] input in snake_notation
|
64
|
+
# @param to_symbol [Boolean] default false (defines if returned keys will be symbols or strings)
|
65
|
+
# @return [Hash|Array] input converted into the (lower) camelCase notation
|
53
66
|
def self.to_lower_camel(input, to_symbol = false)
|
54
67
|
|
55
68
|
conversion_logic = lambda do |k|
|
@@ -60,6 +73,11 @@ class NotationConverter
|
|
60
73
|
|
61
74
|
end
|
62
75
|
|
76
|
+
# Converts passed input to snake_notation
|
77
|
+
#
|
78
|
+
# @param input [Hash|Array] input in camelCase notation
|
79
|
+
# @param to_symbol [Boolean] default false (defines if returned keys will be symbols or strings)
|
80
|
+
# @return [Hash|Array] input converted into the snake_notation
|
63
81
|
def self.to_snake(input, to_symbol = false)
|
64
82
|
|
65
83
|
conversion_logic = lambda do |k|
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: notation_converter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mariusz Karpicki
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-09-
|
11
|
+
date: 2017-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: NotationConverter allows to convert between
|
13
|
+
description: NotationConverter allows to convert between snake_notation and camelCase
|
14
|
+
notation
|
14
15
|
email: mkarpicki@gmail.com
|
15
16
|
executables: []
|
16
17
|
extensions: []
|