notation_converter 1.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/notation_converter.rb +74 -0
  3. metadata +44 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f17f576ce4a9fbb101404e0cd555f50386eb145c
4
+ data.tar.gz: d3b7df9fdb4132e7d5132003084ad005e3a69def
5
+ SHA512:
6
+ metadata.gz: 411ed7e5f5d2eeda6cbfea3c3f8f1d28f18725b9506bba68881f9fb18b3849e24ed7a35abc28364ee2d2c233064f2edf2d458f649124cb1b4ad760b9067afa9b
7
+ data.tar.gz: 5045ea5937a4b08d7f5659cf1f2d6c523e3e20c19aa8c377ca10e5af6df16c781df85134b4319c2e4ebed10b896831482852ccf4d7b0fe20a8966d22f85997e0
@@ -0,0 +1,74 @@
1
+ class NotationConverter
2
+
3
+ def self.convert_input(input, &conversion_logic)
4
+
5
+ unless input.nil?
6
+
7
+ new_input = {}
8
+
9
+ if input.kind_of? Struct
10
+
11
+ elsif input.kind_of? Hash
12
+ input.each_pair do |k,v|
13
+ new_k = conversion_logic.call(k)
14
+ new_input[new_k] = (convert_input v, &conversion_logic)
15
+ end
16
+ elsif input.kind_of? Array
17
+ new_input = input.map do |elem|
18
+ convert_input elem, &conversion_logic
19
+ end
20
+ #elsif input.kind_of? Object
21
+
22
+ else
23
+ new_input = input
24
+ end
25
+
26
+ new_input
27
+ end
28
+
29
+ end
30
+
31
+ def self.return_val (k, to_symbol)
32
+ (to_symbol) ? k.to_sym : k
33
+ end
34
+
35
+ def self.to_camel(input, type = :lower, to_symbol = false)
36
+ if type == :upper
37
+ to_upper_camel input, to_symbol
38
+ else
39
+ to_lower_camel input, to_symbol
40
+ end
41
+ end
42
+
43
+ def self.to_upper_camel(input, to_symbol = false)
44
+
45
+ conversion_logic = lambda do |k|
46
+ new_k = k.to_s.split('_').map.with_index{|e, i| e.capitalize }.join
47
+ return_val new_k, to_symbol
48
+ end
49
+ convert_input input, &conversion_logic
50
+
51
+ end
52
+
53
+ def self.to_lower_camel(input, to_symbol = false)
54
+
55
+ conversion_logic = lambda do |k|
56
+ new_k = k.to_s.split('_').map.with_index{|e, i| i == 0 ? e : e.capitalize }.join
57
+ return_val new_k, to_symbol
58
+ end
59
+ convert_input input, &conversion_logic
60
+
61
+ end
62
+
63
+ def self.to_snake(input, to_symbol = false)
64
+
65
+ conversion_logic = lambda do |k|
66
+ new_k = k.gsub(/(.)([A-Z])/,'\1_\2').downcase
67
+ return_val new_k, to_symbol
68
+ end
69
+ convert_input input, &conversion_logic
70
+
71
+ end
72
+
73
+ private_class_method :convert_input, :return_val
74
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: notation_converter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Mariusz Karpicki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: NotationConverter allows to convert between snake and camel notations
14
+ email: mkarpicki@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/notation_converter.rb
20
+ homepage: http://rubygems.org/gems/notation_converter
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubyforge_project:
40
+ rubygems_version: 2.6.11
41
+ signing_key:
42
+ specification_version: 4
43
+ summary: Conversion between notations
44
+ test_files: []