aromat 1.3.1 → 1.4.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.
- checksums.yaml +4 -4
- data/README.md +19 -8
- data/lib/aromat/str_keys.rb +24 -0
- data/lib/aromat/version.rb +1 -1
- 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: 58cfb008b961e3d3e110567fd8bbe76054d8989a
|
|
4
|
+
data.tar.gz: da20e4a3b501feef330b4843e296dc735df9d411
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 68d72a1005d1bdb483406f073ddc847123ee27b331185b1e5c851d6a3de3e256582719af3152f272fa058a2e850be972e9746721aa12a442da11d46b8dcf5cf8
|
|
7
|
+
data.tar.gz: 4430a210d315eb9f73d99a52055178bb95a18f0de68c4e7d7c02eafb56fb276ce055b407f1cfcb257336c9b88de6bd9c7f504f4136c2e51d7721d37f8bac952f
|
data/README.md
CHANGED
|
@@ -31,6 +31,17 @@ a.sym_keys
|
|
|
31
31
|
# => {:foo=>"bar", :nested=>[{:problems=>"none"}]}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
+
### Stringize Keys
|
|
35
|
+
|
|
36
|
+
A _str_keys_ method is monkey-patched into the *Array* and *Hash* classes, and provides a way to recursively convert *keys* to *strings*.
|
|
37
|
+
This is pretty much the opposite of the 'sym_keys' feature presented just above.
|
|
38
|
+
|
|
39
|
+
```ruby
|
|
40
|
+
a = { foo: 'bar', nested: [{ problems: 'none' }] }
|
|
41
|
+
a.sym_keys
|
|
42
|
+
# => {"foo"=>"bar", "nested"=>[{"problems"=>"none"}]}
|
|
43
|
+
```
|
|
44
|
+
|
|
34
45
|
### Deep-clone
|
|
35
46
|
|
|
36
47
|
A _dclone_ method is monkey-patched into the *Array* and *Hash* classes, and provides a way to recursively *deep-clone* an instance.
|
|
@@ -103,8 +114,8 @@ nil.try :nstr
|
|
|
103
114
|
|
|
104
115
|
Case-conversion methods are monkey-patched into the *String* class. The following methods are made available:
|
|
105
116
|
* camelcase ('foo-bar' => 'FooBar')
|
|
106
|
-
* snakecase ('FooBar' => '
|
|
107
|
-
* kebabcase ('FooBar' => '
|
|
117
|
+
* snakecase ('FooBar' => 'foo_bar')
|
|
118
|
+
* kebabcase ('FooBar' => 'foo-bar')
|
|
108
119
|
|
|
109
120
|
```ruby
|
|
110
121
|
'foo_bar'.camelcase
|
|
@@ -113,14 +124,14 @@ Case-conversion methods are monkey-patched into the *String* class. The followin
|
|
|
113
124
|
# => 'FooBar'
|
|
114
125
|
|
|
115
126
|
'FooBar'.snakecase
|
|
116
|
-
# => 'foo-bar'
|
|
117
|
-
'foo_bar'.snakecase
|
|
118
|
-
# => 'foo-bar'
|
|
119
|
-
|
|
120
|
-
'FooBar'.kebabcase
|
|
121
127
|
# => 'foo_bar'
|
|
122
|
-
'foo-bar'.
|
|
128
|
+
'foo-bar'.snakecase
|
|
123
129
|
# => 'foo_bar'
|
|
130
|
+
|
|
131
|
+
'FooBar'.kebabcase
|
|
132
|
+
# => 'foo-bar'
|
|
133
|
+
'foo_bar'.kebabcase
|
|
134
|
+
# => 'foo-bar'
|
|
124
135
|
```
|
|
125
136
|
|
|
126
137
|
### Next / Last weekday
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# Aromat
|
|
2
|
+
# by Eresse <eresse@eresse.net>
|
|
3
|
+
|
|
4
|
+
# Monkey-patch Array Class
|
|
5
|
+
class Array
|
|
6
|
+
|
|
7
|
+
# Stringize Keys:
|
|
8
|
+
# Recursively stringizes hash keys.
|
|
9
|
+
# @return [Array] A copy of the original array where each element has had its keys recursively stringized
|
|
10
|
+
def str_keys
|
|
11
|
+
collect { |e| e.respond_to?(:str_keys) ? e.str_keys : e }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Monkey-patch Hash Class
|
|
16
|
+
class Hash
|
|
17
|
+
|
|
18
|
+
# Stringize Keys:
|
|
19
|
+
# Recursively stringizes hash keys.
|
|
20
|
+
# @return [Hash] A copy of the original hash where each element has had its keys recursively stringized
|
|
21
|
+
def str_keys
|
|
22
|
+
Hash[*(inject([]) { |a, e| (a << (e[0].is_a?(Symbol) ? e[0].to_s : e[0])) << (e[1].respond_to?(:str_keys) ? e[1].str_keys : e[1]) })]
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/aromat/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aromat
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Eresse
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2018-10-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -73,6 +73,7 @@ files:
|
|
|
73
73
|
- lib/aromat/module.rb
|
|
74
74
|
- lib/aromat/nstr.rb
|
|
75
75
|
- lib/aromat/pad.rb
|
|
76
|
+
- lib/aromat/str_keys.rb
|
|
76
77
|
- lib/aromat/sym_keys.rb
|
|
77
78
|
- lib/aromat/try.rb
|
|
78
79
|
- lib/aromat/version.rb
|
|
@@ -96,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
96
97
|
version: '0'
|
|
97
98
|
requirements: []
|
|
98
99
|
rubyforge_project:
|
|
99
|
-
rubygems_version: 2.
|
|
100
|
+
rubygems_version: 2.6.13
|
|
100
101
|
signing_key:
|
|
101
102
|
specification_version: 4
|
|
102
103
|
summary: Small extensions to Ruby core libraries to make your life easier
|