string-cases 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/README.md +16 -0
- data/VERSION +1 -1
- data/lib/string-cases.rb +27 -0
- data/spec/string-cases_spec.rb +22 -0
- data/string-cases.gemspec +4 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 000023f3208493ee8e5b7946040ffa6ecc4282cf
|
4
|
+
data.tar.gz: b58642e71de68780ac514567e48f3c5f8d376a69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bef5509e708606265e5c91ca369fc7a7329b3291e96480899ac6c082a5aad62d46a9e09113204c946ab05be2131a9edc66e7116d30056c90882c7e5d879ae37
|
7
|
+
data.tar.gz: 80cab67dcf2e73aae4a4af81f1e74afe1f7ddcda8eb8de95bd35c924fa6b056db9265a54f8bb3049c9f34601c3a1929bae2777b739fb52154a2b226d1a3c83ed
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -42,6 +42,22 @@ StringCases.singularize("users") #=> "user"
|
|
42
42
|
StringCases.singularize("categories") #=> "category"
|
43
43
|
```
|
44
44
|
|
45
|
+
### Constantize
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
StringCases.constantize("SomeNamespace::SomeClass") => SomeNamespace::SomeClass
|
49
|
+
```
|
50
|
+
|
51
|
+
### Symbolize keys
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
StringCases.symbolize_keys({"test1" => "test1val", "test2" => {"test2key" => "test2val"}}, recursive: true) #=> {:test1 => "test1val, :test2 => {:test2key => "test2val"}}
|
55
|
+
```
|
56
|
+
|
57
|
+
```ruby
|
58
|
+
StringCases.stringify_keys({test1: "test1val", test2: {test2key: "test2val"}}, recursive: true) #=> {"test1" => "test1val, "test2" => {"test2key" => "test2val"}}
|
59
|
+
```
|
60
|
+
|
45
61
|
## Contributing to string-cases
|
46
62
|
|
47
63
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.4
|
data/lib/string-cases.rb
CHANGED
@@ -36,4 +36,31 @@ class StringCases
|
|
36
36
|
mod_path.const_get(mod_to_find)
|
37
37
|
end
|
38
38
|
end
|
39
|
+
|
40
|
+
def self.hash_keys(hash, mode, args = {})
|
41
|
+
new_hash = {}
|
42
|
+
hash.each do |key, value|
|
43
|
+
case mode
|
44
|
+
when :stringify
|
45
|
+
key = key.to_s if key.is_a?(Symbol)
|
46
|
+
when :symbolize
|
47
|
+
key = key.to_sym if key.is_a?(String)
|
48
|
+
else
|
49
|
+
raise "Unknown mode: #{mode}"
|
50
|
+
end
|
51
|
+
|
52
|
+
value = StringCases.hash_keys(value, mode, args) if args[:recursive] && value.is_a?(Hash)
|
53
|
+
new_hash[key] = value
|
54
|
+
end
|
55
|
+
|
56
|
+
new_hash
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.symbolize_keys(hash, args = {})
|
60
|
+
StringCases.hash_keys(hash, :symbolize, args)
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.stringify_keys(hash, args = {})
|
64
|
+
StringCases.hash_keys(hash, :stringify, args)
|
65
|
+
end
|
39
66
|
end
|
data/spec/string-cases_spec.rb
CHANGED
@@ -41,4 +41,26 @@ describe "StringCases" do
|
|
41
41
|
expect(StringCases.constantize("WeakRef::RefError")).to eq WeakRef::RefError
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
describe "#hash_keys" do
|
46
|
+
it "symbolizes keys" do
|
47
|
+
result = StringCases.symbolize_keys("test1" => "test1val", "test2" => {"test3" => "test3val"})
|
48
|
+
expect(result).to eq(test1: "test1val", test2: {"test3" => "test3val"})
|
49
|
+
end
|
50
|
+
|
51
|
+
it "stringify keys" do
|
52
|
+
result = StringCases.stringify_keys(test1: "test1val", test2: {test3: "test3val"})
|
53
|
+
expect(result).to eq("test1" => "test1val", "test2" => {test3: "test3val"})
|
54
|
+
end
|
55
|
+
|
56
|
+
it "symbolizes keys recursively" do
|
57
|
+
result = StringCases.symbolize_keys({"test1" => "test1val", "test2" => {"test3" => "test3val"}}, recursive: true)
|
58
|
+
expect(result).to eq(test1: "test1val", test2: {test3: "test3val"})
|
59
|
+
end
|
60
|
+
|
61
|
+
it "stringify keys recursively" do
|
62
|
+
result = StringCases.stringify_keys({test1: "test1val", test2: {test3: "test3val"}}, recursive: true)
|
63
|
+
expect(result).to eq("test1" => "test1val", "test2" => {"test3" => "test3val"})
|
64
|
+
end
|
65
|
+
end
|
44
66
|
end
|
data/string-cases.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: string-cases 0.0.
|
5
|
+
# stub: string-cases 0.0.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "string-cases"
|
9
|
-
s.version = "0.0.
|
9
|
+
s.version = "0.0.4"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["kaspernj"]
|
14
|
-
s.date = "2016-01-
|
14
|
+
s.date = "2016-01-10"
|
15
15
|
s.description = "Small gem for converting various string-cases to other cases."
|
16
16
|
s.email = "k@spernj.org"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -36,7 +36,7 @@ Gem::Specification.new do |s|
|
|
36
36
|
]
|
37
37
|
s.homepage = "http://github.com/kaspernj/string-cases"
|
38
38
|
s.licenses = ["MIT"]
|
39
|
-
s.rubygems_version = "2.
|
39
|
+
s.rubygems_version = "2.2.2"
|
40
40
|
s.summary = "Small gem for converting various string-cases to other cases."
|
41
41
|
|
42
42
|
if s.respond_to? :specification_version then
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string-cases
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kaspernj
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-01-
|
11
|
+
date: 2016-01-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -122,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
122
|
version: '0'
|
123
123
|
requirements: []
|
124
124
|
rubyforge_project:
|
125
|
-
rubygems_version: 2.
|
125
|
+
rubygems_version: 2.2.2
|
126
126
|
signing_key:
|
127
127
|
specification_version: 4
|
128
128
|
summary: Small gem for converting various string-cases to other cases.
|