evt-casing 0.2.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: '08612fcd3cec4586337b3ad786c4cb97eaf690de'
4
+ data.tar.gz: 237a7a68509a0f5586c0c615f2b77106b439c901
5
+ SHA512:
6
+ metadata.gz: f340c17709ef45a78d0a4b742c0ce1a658247e39fe802eff62361d5d278122a74cbea377b0b408543582f135d77ff138799ea890166026e9f43b9ece40c34888
7
+ data.tar.gz: 952f283d298b939378ac1ab762cfa0cd87b69b1829e958929f7cbaf0137b5c9c2b521c57671cbf1bd492e90ff18cb60b1c59a1feccb32dd99558dd05099eaef2
@@ -0,0 +1,16 @@
1
+ require 'casing/casing'
2
+
3
+ require 'casing/camel/string'
4
+ require 'casing/camel/array'
5
+ require 'casing/camel/hash'
6
+ require 'casing/camel'
7
+
8
+ require 'casing/pascal/string'
9
+ require 'casing/pascal/array'
10
+ require 'casing/pascal/hash'
11
+ require 'casing/pascal'
12
+
13
+ require 'casing/underscore/string'
14
+ require 'casing/underscore/array'
15
+ require 'casing/underscore/hash'
16
+ require 'casing/underscore'
@@ -0,0 +1,9 @@
1
+ module Casing
2
+ class Camel
3
+ extend Casing
4
+
5
+ def self.match?(val)
6
+ (val =~ /^[a-z]/) && !(val =~ /_/)
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Casing
2
+ class Camel
3
+ module Array
4
+ def self.call(val, include_values: nil, symbol_to_string: nil)
5
+ include_values = include_values.nil? ? false : include_values
6
+ symbol_to_string ||= false
7
+
8
+ val.map do |v|
9
+ Casing::Camel.(v, include_values: include_values, symbol_to_string: symbol_to_string)
10
+ end
11
+ end
12
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Casing
2
+ class Camel
3
+ module Hash
4
+ def self.call(val, include_values: nil, symbol_to_string: nil)
5
+ include_values = include_values.nil? ? false : include_values
6
+ symbol_to_string ||= false
7
+
8
+ ::Hash[val.map { |k, v| [Casing::Camel.(k, include_values: true, symbol_to_string: symbol_to_string), Casing::Camel.(v, include_values: include_values, symbol_to_string: symbol_to_string)] }]
9
+ end
10
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,27 @@
1
+ module Casing
2
+ class Camel
3
+ module String
4
+ def self.call(val, include_values: nil, symbol_to_string: nil)
5
+ include_values = include_values.nil? ? true : include_values
6
+ symbol_to_string ||= false
7
+
8
+ return val unless include_values
9
+ return val if val.length == 0
10
+
11
+ sym = val.is_a?(Symbol)
12
+
13
+ converted = val
14
+ .to_s
15
+ .chars.first.downcase +
16
+ Pascal::String.(val)[1..-1]
17
+
18
+ if !symbol_to_string && sym
19
+ converted = converted.to_sym
20
+ end
21
+
22
+ converted
23
+ end
24
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,74 @@
1
+ module Casing
2
+ class Error < RuntimeError; end
3
+
4
+ def call(val, include_values: nil, symbol_to_string: nil)
5
+ case val
6
+ when ::Hash
7
+ self::Hash.(val, include_values: include_values, symbol_to_string: symbol_to_string)
8
+
9
+ when ::Array
10
+ self::Array.(val, include_values: include_values, symbol_to_string: symbol_to_string)
11
+
12
+ when ::String
13
+ self::String.(val, include_values: include_values, symbol_to_string: symbol_to_string)
14
+
15
+ when ::Symbol
16
+ self::String.(val, include_values: include_values, symbol_to_string: symbol_to_string)
17
+
18
+ else
19
+ val
20
+ end
21
+ end
22
+
23
+ # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
24
+ def !(val, include_values: nil, symbol_to_string: nil)
25
+ call(val, include_values: include_values, symbol_to_string: symbol_to_string)
26
+ end
27
+
28
+ def case?(val, include_values: nil, symbol_to_string: nil)
29
+ include_values ||= false
30
+ symbol_to_string ||= false
31
+
32
+ case val
33
+ when ::Array
34
+ val.each do |v|
35
+ cased = case?(v, include_values: include_values, symbol_to_string: symbol_to_string)
36
+ return false unless cased
37
+ end
38
+
39
+ when ::Hash
40
+ val.each do |k, v|
41
+ value_cased = value_cased?(k, symbol_to_string: symbol_to_string)
42
+ return false unless value_cased
43
+
44
+ cased = case?(v, include_values: include_values, symbol_to_string: symbol_to_string)
45
+ return false unless cased
46
+ end
47
+
48
+ else
49
+ if include_values
50
+ value_cased = value_cased?(val, symbol_to_string: symbol_to_string)
51
+ return false unless value_cased
52
+ end
53
+ end
54
+
55
+ true
56
+ end
57
+
58
+ def value_cased?(val, symbol_to_string: nil)
59
+ symbol_to_string ||= false
60
+
61
+ if symbol_to_string && val.is_a?(Symbol)
62
+ return false
63
+ end
64
+
65
+ val = val.to_s
66
+
67
+ val.split.each do |v|
68
+ cased = match?(v)
69
+ return false unless cased
70
+ end
71
+
72
+ true
73
+ end
74
+ end
@@ -0,0 +1,3 @@
1
+ require 'casing/controls/string'
2
+ require 'casing/controls/array'
3
+ require 'casing/controls/hash'
@@ -0,0 +1,23 @@
1
+ module Casing
2
+ module Controls
3
+ module Array
4
+ def self.example
5
+ [
6
+ 'underscore_value',
7
+ 'PascalValue',
8
+ 'camelValue',
9
+ 'Separate words',
10
+ 'some words'
11
+ ]
12
+ end
13
+
14
+ def self.not_camel_case
15
+ example.delete_if { |e| Casing::Camel.match?(e) }
16
+ end
17
+
18
+ def self.not_underscore_case
19
+ example.delete_if { |e| Casing::Underscore.match?(e) }
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,59 @@
1
+ module Casing
2
+ module Controls
3
+ module Hash
4
+ def self.example
5
+ hash = {}
6
+
7
+ hash.merge! Symbol.example
8
+ hash.merge! String.example
9
+ hash.merge! Nested::Hash.example
10
+ hash.merge! Nested::Array.example
11
+
12
+ hash
13
+ end
14
+
15
+ module Symbol
16
+ def self.example
17
+ {
18
+ :underscore_symbol_key => :underscore_symbol_value,
19
+ :camelSymbolKey => :camelSymbolValue,
20
+ :PascalSymbolKey => :PascalSymbolValue
21
+ }
22
+ end
23
+ end
24
+
25
+ module String
26
+ def self.example
27
+ {
28
+ 'underscore_string_key' => 'underscore_string_value',
29
+ 'camelStringKey' => 'camelStringValue',
30
+ 'PascalStringKey' => 'PascalStringValue'
31
+ }
32
+ end
33
+ end
34
+
35
+ module Nested
36
+ module Hash
37
+ def self.example
38
+ hash = {}
39
+ hash.merge! Symbol.example
40
+ hash.merge! String.example
41
+
42
+ { :nested_hash => hash }
43
+ end
44
+ end
45
+
46
+ module Array
47
+ def self.example
48
+ array = [
49
+ { :array_nested_hash_a => :array_nested_hash_value_a },
50
+ { :array_nested_hash_b => :array_nested_hash_value_b }
51
+ ]
52
+
53
+ { :nested_array => array }
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,53 @@
1
+ module Casing
2
+ module Controls
3
+ module String
4
+ module Underscore
5
+ def self.example
6
+ 'some_string'
7
+ end
8
+
9
+ module Contrary
10
+ def self.example
11
+ 'SomeString'
12
+ end
13
+ end
14
+ end
15
+
16
+ module Pascal
17
+ def self.example
18
+ 'SomeString'
19
+ end
20
+
21
+ module Contrary
22
+ def self.example
23
+ 'someString'
24
+ end
25
+ end
26
+ end
27
+
28
+ module Camel
29
+ def self.example
30
+ 'someString'
31
+ end
32
+
33
+ module Contrary
34
+ def self.example
35
+ 'SomeString'
36
+ end
37
+ end
38
+ end
39
+
40
+ module Symbol
41
+ def self.example
42
+ :some_string
43
+ end
44
+
45
+ module Contrary
46
+ def self.example
47
+ 'SomeString'
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ module Casing
2
+ class Pascal
3
+ extend Casing
4
+
5
+ def self.match?(val)
6
+ !!((val =~ /^[A-Z]/) && (val =~ /[a-z]/))
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ module Casing
2
+ class Pascal
3
+ class Array
4
+ def self.call(*)
5
+ raise Casing::Error, "Array cannot be converted to pascal case"
6
+ end
7
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Casing
2
+ class Pascal
3
+ class Hash
4
+ def self.call(*)
5
+ raise Casing::Error, "Hash cannot be converted to pascal case"
6
+ end
7
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module Casing
2
+ class Pascal
3
+ module String
4
+ def self.call(val, include_values: nil, symbol_to_string: nil)
5
+ include_values = include_values.nil? ? true : include_values
6
+ symbol_to_string ||= false
7
+
8
+ return val unless include_values
9
+
10
+ sym = val.is_a?(Symbol)
11
+
12
+ converted = val
13
+ .to_s
14
+ .gsub(/\/(.?)/) { "::" + $1.upcase }
15
+ .gsub(/(^|_)(.)/) { $2.upcase }
16
+
17
+ if !symbol_to_string && sym
18
+ converted = converted.to_sym
19
+ end
20
+
21
+ converted
22
+ end
23
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ module Casing
2
+ class Underscore
3
+ extend Casing
4
+
5
+ def self.match?(val)
6
+ !!((((val =~ /^[a-z]/) && (val =~ /_/)) || (val =~ /^[a-z]/)) && !(val =~ /[A-Z]/))
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Casing
2
+ class Underscore
3
+ module Array
4
+ def self.call(val, include_values: nil, symbol_to_string: nil)
5
+ include_values = include_values.nil? ? false : include_values
6
+ symbol_to_string ||= false
7
+
8
+ val.map do |v|
9
+ Casing::Underscore.(v, include_values: include_values, symbol_to_string: symbol_to_string)
10
+ end
11
+ end
12
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ module Casing
2
+ class Underscore
3
+ module Hash
4
+ def self.call(val, include_values: nil, symbol_to_string: nil)
5
+ include_values = include_values.nil? ? false : include_values
6
+ symbol_to_string ||= false
7
+
8
+ ::Hash[val.map { |k, v| [Casing::Underscore.(k, include_values: true, symbol_to_string: symbol_to_string), Casing::Underscore.(v, include_values: include_values, symbol_to_string: symbol_to_string)] }]
9
+ end
10
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,29 @@
1
+ module Casing
2
+ class Underscore
3
+ module String
4
+ def self.call(val, include_values: nil, symbol_to_string: nil)
5
+ include_values = include_values.nil? ? true : include_values
6
+ symbol_to_string ||= false
7
+
8
+ return val unless include_values
9
+
10
+ sym = val.is_a?(Symbol)
11
+
12
+ converted = val
13
+ .to_s
14
+ .gsub(/::/, '/')
15
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
16
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
17
+ .tr('-', '_')
18
+ .downcase
19
+
20
+ if !symbol_to_string && sym
21
+ converted = converted.to_sym
22
+ end
23
+
24
+ converted
25
+ end
26
+ class << self; alias :! :call; end # TODO: Remove deprecated actuator [Kelsey, Thu Oct 08 2015]
27
+ end
28
+ end
29
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: evt-casing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - The Eventide Project
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ntl-test_bench
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: evt-telemetry-logger
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: " "
42
+ email: opensource@eventide-project.org
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - lib/casing.rb
48
+ - lib/casing/camel.rb
49
+ - lib/casing/camel/array.rb
50
+ - lib/casing/camel/hash.rb
51
+ - lib/casing/camel/string.rb
52
+ - lib/casing/casing.rb
53
+ - lib/casing/controls.rb
54
+ - lib/casing/controls/array.rb
55
+ - lib/casing/controls/hash.rb
56
+ - lib/casing/controls/string.rb
57
+ - lib/casing/pascal.rb
58
+ - lib/casing/pascal/array.rb
59
+ - lib/casing/pascal/hash.rb
60
+ - lib/casing/pascal/string.rb
61
+ - lib/casing/underscore.rb
62
+ - lib/casing/underscore/array.rb
63
+ - lib/casing/underscore/hash.rb
64
+ - lib/casing/underscore/string.rb
65
+ homepage: https://github.com/eventide-project/casing
66
+ licenses:
67
+ - MIT
68
+ metadata: {}
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: 2.3.3
78
+ required_rubygems_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 2.5.2
86
+ signing_key:
87
+ specification_version: 4
88
+ summary: Convert the case of strings, symbols, and hash keys, including camelCase,
89
+ PascalCase, and underscore_case
90
+ test_files: []