hash_extensions 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.
- checksums.yaml +7 -0
- data/lib/hash_extensions.rb +33 -0
- metadata +59 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e0fbf4578e0dc9577fd5632d94bc9beb5425af0
|
4
|
+
data.tar.gz: 5434da066ac38066259b2c8005ca18361c76b128
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 27e4df7b7fa33ab30463b027e098dae043f085d45e9a9e6ce80d56c97044e0cb169293d763989863a4262c8b76c5b72d95401c403b6ba3c30871f33032baa374
|
7
|
+
data.tar.gz: 64f8bcd1b6c2b5a75dd83f00118177643fe65770ccf28baf9527e1add60a6a895724eced41078c298142f2abef7c54239e41a980317c656c46da904e3cc38ba5
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
|
3
|
+
class Hash
|
4
|
+
# Search for key path in hash
|
5
|
+
#
|
6
|
+
# == Examples
|
7
|
+
#
|
8
|
+
# { a: { b: :c } }.dig(:a, :b) # => :c
|
9
|
+
# { a: { 'b' => :c } }.dig(:a, :b) # => :c
|
10
|
+
# { a: { b: :c } }.dig(:a, :c) # => nil
|
11
|
+
def dig(*path)
|
12
|
+
path.reduce(self) do |location, key|
|
13
|
+
location.respond_to?(:keys) ? location.stringify_keys[key.to_s] : nil
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Search the Hash deeply for all values matching the +key+.
|
18
|
+
#
|
19
|
+
# == Examples
|
20
|
+
#
|
21
|
+
# { a: :b, c: { a: '1', d: :e } }.values_for('a') # => [:b, '1']
|
22
|
+
def values_for(key)
|
23
|
+
found_values = []
|
24
|
+
self.each do |k, v|
|
25
|
+
found_values << v if k.to_s == key.to_s
|
26
|
+
if v.is_a? Hash
|
27
|
+
found_values << v.values_for(key)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
found_values.flatten.compact
|
32
|
+
end
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hash_extensions
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Emil Kampp
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
description: Some common, practical hash hash_extensions
|
28
|
+
email: emil@kampp.me
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/hash_extensions.rb
|
34
|
+
homepage: https://github.com/ekampp/hash_extensions
|
35
|
+
licenses:
|
36
|
+
- MIT
|
37
|
+
metadata: {}
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
require_paths:
|
41
|
+
- lib
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
requirements: []
|
53
|
+
rubyforge_project:
|
54
|
+
rubygems_version: 2.4.5
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: Some common, practical hash hash_extensions
|
58
|
+
test_files: []
|
59
|
+
has_rdoc:
|