hash_extensions 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hash_extensions.rb +2 -26
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b743172dcd1317fa9144ac6c0c9f55a00c2d021d
|
4
|
+
data.tar.gz: e36af1ddc1be7c28b06109a234f601ca209bb299
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 848db76695fcdca213a9dce66d7605b3d2a2dc80945663a2fc5ad435b270fbf1f151d27b6bad0fbd4601f4f6f6f29fbb3327750d0731c3f821b90f71c807ecf4
|
7
|
+
data.tar.gz: 3344e822e7f6ed718b0c6f6dfe61aeaba3c8805c4037e9307eb393d850312e5a859c03f071d3fe24d9bfd6a8d279841ce69e041a1bd9267e2d686a32ea9739fd
|
data/lib/hash_extensions.rb
CHANGED
@@ -3,7 +3,7 @@ require 'active_support/all'
|
|
3
3
|
class Hash
|
4
4
|
# Search for key path in hash
|
5
5
|
#
|
6
|
-
#
|
6
|
+
# Examples
|
7
7
|
#
|
8
8
|
# { a: { b: :c } }.dig(:a, :b) # => :c
|
9
9
|
# { a: { 'b' => :c } }.dig(:a, :b) # => :c
|
@@ -16,7 +16,7 @@ class Hash
|
|
16
16
|
|
17
17
|
# Search the Hash deeply for all values matching the +key+.
|
18
18
|
#
|
19
|
-
#
|
19
|
+
# Examples
|
20
20
|
#
|
21
21
|
# { a: :b, c: { a: '1', d: :e } }.values_for('a') # => [:b, '1']
|
22
22
|
def values_for(key)
|
@@ -30,28 +30,4 @@ class Hash
|
|
30
30
|
|
31
31
|
found_values.flatten.compact
|
32
32
|
end
|
33
|
-
|
34
|
-
# Flattens the hash keys recursively
|
35
|
-
#
|
36
|
-
# == Examples
|
37
|
-
#
|
38
|
-
# { a: :b, c: { d: :e } }.recursive_flat_map # => [ :a, :c, :d ]
|
39
|
-
def recursive_flat_map
|
40
|
-
a = flat_map do |k, v|
|
41
|
-
v = v.respond_to?(:recursive_flat_map) ? v.recursive_flat_map : nil
|
42
|
-
[k, v].compact
|
43
|
-
end
|
44
|
-
a.flatten
|
45
|
-
end
|
46
|
-
|
47
|
-
# Recursively flattens and sorts a hash into its keys and values.
|
48
|
-
#
|
49
|
-
# == Examples
|
50
|
-
#
|
51
|
-
# { c: { d: :e }, a: :b, f: ['g', 'h'] }.recursive_flatten # => [:a, :b, :c, :d, :e, :f, 'g', 'h']
|
52
|
-
def recursive_flatten
|
53
|
-
sort.flat_map do |k, v|
|
54
|
-
[k, v.respond_to?(:recursive_flatten) ? v.recursive_flatten : v].compact
|
55
|
-
end.flatten
|
56
|
-
end
|
57
33
|
end
|
metadata
CHANGED
@@ -1,29 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Emil Kampp
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-11-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '4.2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.3'
|
27
41
|
description: Some common, practical hash hash_extensions
|
28
42
|
email: emil@kampp.me
|
29
43
|
executables: []
|
@@ -51,7 +65,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
51
65
|
version: '0'
|
52
66
|
requirements: []
|
53
67
|
rubyforge_project:
|
54
|
-
rubygems_version: 2.4.5
|
68
|
+
rubygems_version: 2.4.5.1
|
55
69
|
signing_key:
|
56
70
|
specification_version: 4
|
57
71
|
summary: Some common, practical hash hash_extensions
|