hash_digger 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +96 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/hash_digger.gemspec +48 -0
- data/lib/hash_digger.rb +100 -0
- data/lib/hash_digger/version.rb +3 -0
- metadata +201 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 520637fc5cf1e79dc8a9362c15a90906df2d9cce6e493ca3c3da8704a3cfed0d
|
4
|
+
data.tar.gz: a9270b9064d2cf3a015f0b1173bd4cdc70b4bbe05ae1585e554be4b888beadfd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88fd1fb61415566dc8a27500fae1794bad1e661b70cb12945a4db3d11ccc5fbffae05c5dc80aee00772e8dcc53a1d2a896ebf9c1d3b599e45ec1da0ec285a1b9
|
7
|
+
data.tar.gz: e332cd0e6bbb8b2acd2656a3e0fcbf296468bbc02b9d67b7b7d69463e78fec5d46ec2d783e69381584b1275eb60fb6907b19c881af1fb62d352aaa75555aab9f
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at smileart21@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
hash_digger (0.0.2)
|
5
|
+
activesupport (> 3.0.1)
|
6
|
+
ruby-try (~> 1.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (5.2.2)
|
12
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
|
+
i18n (>= 0.7, < 2)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
tzinfo (~> 1.1)
|
16
|
+
ansi (1.5.0)
|
17
|
+
awesome_print (1.8.0)
|
18
|
+
builder (3.2.3)
|
19
|
+
byebug (10.0.2)
|
20
|
+
colorize (0.8.1)
|
21
|
+
concurrent-ruby (1.1.4)
|
22
|
+
i18n (1.2.0)
|
23
|
+
concurrent-ruby (~> 1.0)
|
24
|
+
letters (0.4.1)
|
25
|
+
activesupport
|
26
|
+
awesome_print
|
27
|
+
colorize
|
28
|
+
xml-simple
|
29
|
+
m (1.5.1)
|
30
|
+
method_source (>= 0.6.7)
|
31
|
+
rake (>= 0.9.2.2)
|
32
|
+
method_source (0.9.2)
|
33
|
+
minitest (5.11.3)
|
34
|
+
minitest-reporters (1.3.5)
|
35
|
+
ansi
|
36
|
+
builder
|
37
|
+
minitest (>= 5.0)
|
38
|
+
ruby-progressbar
|
39
|
+
rake (10.5.0)
|
40
|
+
ruby-progressbar (1.10.0)
|
41
|
+
ruby-try (1.1.1)
|
42
|
+
thread_safe (0.3.6)
|
43
|
+
tzinfo (1.2.5)
|
44
|
+
thread_safe (~> 0.1)
|
45
|
+
xml-simple (1.1.5)
|
46
|
+
|
47
|
+
PLATFORMS
|
48
|
+
ruby
|
49
|
+
x86_64-darwin-17
|
50
|
+
|
51
|
+
DEPENDENCIES
|
52
|
+
awesome_print (~> 1.8)
|
53
|
+
bundler (~> 1.17)
|
54
|
+
byebug (~> 10.0)
|
55
|
+
hash_digger!
|
56
|
+
letters (~> 0.4)
|
57
|
+
m (~> 1.5)
|
58
|
+
minitest (~> 5.11)
|
59
|
+
minitest-reporters (~> 1.3)
|
60
|
+
rake (~> 10.0)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Serge Bedzhyk
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
# 👷🕳 HashDigger
|
2
|
+
|
3
|
+
> A utilitarian lib to extract data from complex Hashes using String path with "recursions".
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'hash_digger'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install hash_digger
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
````ruby
|
24
|
+
_h = {a: 1, b: 2}
|
25
|
+
p HashDigger::Digger.dig(data: _h, path: '*') # => {:a=>1, :b=>2}
|
26
|
+
p HashDigger::Digger.dig(data: _h, path: 'b') # => 2
|
27
|
+
|
28
|
+
_a = [1, 2, 3]
|
29
|
+
p HashDigger::Digger.dig(data: _a, path: '*') # => [1, 2, 3]
|
30
|
+
p HashDigger::Digger.dig(data: _a, path: '2') # => 3
|
31
|
+
|
32
|
+
ah = [{a: 42}, {a: 13, b: 7}]
|
33
|
+
p HashDigger::Digger.dig(data: ah, path: '*.a') # => [42, 13]
|
34
|
+
p HashDigger::Digger.dig(data: ah, path: '*.b', strict: false) # => [nil, 7]
|
35
|
+
p HashDigger::Digger.dig(data: ah, path: '*.b', strict: false) { |result| result.compact } # => [7]
|
36
|
+
|
37
|
+
ha = {a: [1, 2, 3], b: [4, 5, 6]}
|
38
|
+
p HashDigger::Digger.dig(data: ha, path: '*') # => {:a=>[1, 2, 3], :b=>[4, 5, 6]}
|
39
|
+
p HashDigger::Digger.dig(data: ha, path: 'a.2') # => 3
|
40
|
+
p HashDigger::Digger.dig(data: ha, path: 'b.0') # => 4
|
41
|
+
|
42
|
+
aha = [{a: 42, b: 13}, [1, 2, 3]]
|
43
|
+
p HashDigger::Digger.dig(data: aha, path: '*') # => [{:a=>42, :b=>13}, [1, 2, 3]]
|
44
|
+
p HashDigger::Digger.dig(data: aha, path: '*.0', strict: false) # => [nil, 1]
|
45
|
+
|
46
|
+
hah = {a: [1, 2, 3], b: {a: 13, b: 42}}
|
47
|
+
p HashDigger::Digger.dig(data: hah, path: '*') # => {:a=>[1, 2, 3], :b=>{:a=>13, :b=>42}}
|
48
|
+
p HashDigger::Digger.dig(data: hah, path: 'a') # => [1, 2, 3]
|
49
|
+
p HashDigger::Digger.dig(data: hah, path: 'a.*') # => [1, 2, 3]
|
50
|
+
p HashDigger::Digger.dig(data: hah, path: 'b.b') # => 42
|
51
|
+
|
52
|
+
aah = [[{a: 1}, {b: 2}], [{a: 1}, {c: 3}]]
|
53
|
+
p HashDigger::Digger.dig(data: aah, path: '*.*.a', strict: false) # => [1, nil, 1, nil]
|
54
|
+
p HashDigger::Digger.dig(data: aah, path: '*.*.a', strict: false) { |result| result.compact } # => [1, 1]
|
55
|
+
|
56
|
+
hhh = {a: {b: {c: {d: 'data'}}}}
|
57
|
+
p HashDigger::Digger.dig(data: hhh, path: 'a.b.c.d') # => "data"
|
58
|
+
|
59
|
+
# => Correct error being raised! YAY! HashDigger::DigError
|
60
|
+
begin
|
61
|
+
p HashDigger::Digger.dig(data: hhh, path: 'a.b.z.d')
|
62
|
+
rescue HashDigger::DigError => e
|
63
|
+
puts "Correct error being raised! YAY! #{e.class}"
|
64
|
+
end
|
65
|
+
|
66
|
+
hahah = {a: {b: 42 }, c: [{d: [{test: 'ok'}, {test: 'well'}]}]}
|
67
|
+
p HashDigger::Digger.dig(data: hahah, path: 'c.*.d.*') # => [[{:test=>"ok"}, {:test=>"well"}]]
|
68
|
+
p HashDigger::Digger.dig(data: hahah, path: 'c.*.d.*.*') # => [{:test=>"ok"}, {:test=>"well"}]
|
69
|
+
|
70
|
+
hhhah = {a: {b: {c: {d: [{info: 42}, {info: 13}, {something: 'test'}]}}}}
|
71
|
+
p HashDigger::Digger.dig(data: hhhah, path: 'a.b.c.d.*.info', strict: false) # => [42, 13, nil]
|
72
|
+
p HashDigger::Digger.dig(data: hhhah, path: 'a.b.c.d.*.info', strict: false, default: '<ERROR>') # => [42, 13, "<ERROR>"]
|
73
|
+
p HashDigger::Digger.dig(data: hhhah, path: 'a.b.c.d.*.something', strict: false) # [nil, nil, "test"]
|
74
|
+
|
75
|
+
p (HashDigger::Digger.dig(data: hhhah, path: 'a.b.c.d.*.something', strict: false) do |result|
|
76
|
+
result.map {|node| node.nil? ? 'OK' : node }
|
77
|
+
end) # ["OK", "OK", "test"]
|
78
|
+
````
|
79
|
+
|
80
|
+
## Development
|
81
|
+
|
82
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
83
|
+
|
84
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/smileart/hash_digger. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
89
|
+
|
90
|
+
## License
|
91
|
+
|
92
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
93
|
+
|
94
|
+
## Code of Conduct
|
95
|
+
|
96
|
+
Everyone interacting in the HashDigger project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/smileart/hash_digger/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "hash_digger"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/hash_digger.gemspec
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'hash_digger/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'hash_digger'
|
7
|
+
spec.version = HashDigger::VERSION
|
8
|
+
spec.authors = ['Serge Bedzhyk']
|
9
|
+
spec.email = ['smileart21@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = %q{Hash Digger (improved)}
|
12
|
+
spec.description = %q{A utilitarian lib to extract data from complex Hashes using String path with recursions}
|
13
|
+
spec.homepage = 'https://github.com/smileart/hash_digger'
|
14
|
+
spec.license = 'MIT'
|
15
|
+
|
16
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
17
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
18
|
+
if spec.respond_to?(:metadata)
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = 'https://github.com/smileart/hash_digger'
|
23
|
+
else
|
24
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
25
|
+
'public gem pushes.'
|
26
|
+
end
|
27
|
+
|
28
|
+
# Specify which files should be added to the gem when it is released.
|
29
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
30
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
32
|
+
end
|
33
|
+
spec.bindir = 'exe'
|
34
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
35
|
+
spec.require_paths = ['lib']
|
36
|
+
|
37
|
+
spec.add_development_dependency 'bundler', '~> 1.17'
|
38
|
+
spec.add_development_dependency 'minitest', '~> 5.11'
|
39
|
+
spec.add_development_dependency 'm', '~> 1.5'
|
40
|
+
spec.add_development_dependency 'minitest-reporters', '~> 1.3'
|
41
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
42
|
+
spec.add_development_dependency 'byebug', '~> 10.0'
|
43
|
+
spec.add_development_dependency 'letters', '~> 0.4'
|
44
|
+
spec.add_development_dependency 'awesome_print', '~> 1.8'
|
45
|
+
|
46
|
+
spec.add_runtime_dependency 'activesupport', '~> 3.0'
|
47
|
+
spec.add_runtime_dependency 'ruby-try', '~> 1.1'
|
48
|
+
end
|
data/lib/hash_digger.rb
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative './hash_digger/version'
|
2
|
+
|
3
|
+
require 'ruby-try'
|
4
|
+
require 'awesome_print'
|
5
|
+
require 'active_support/core_ext/object/blank'
|
6
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
7
|
+
|
8
|
+
require 'byebug' if ENV['DEBUG']
|
9
|
+
require 'letters' if ENV['DEBUG']
|
10
|
+
|
11
|
+
module HashDigger
|
12
|
+
class DigError < Exception; end
|
13
|
+
|
14
|
+
class Digger
|
15
|
+
class << self
|
16
|
+
def dig(data:, path:, strict: true, default: nil)
|
17
|
+
if data.respond_to?(:keys)
|
18
|
+
data = data.deep_symbolize_keys
|
19
|
+
end
|
20
|
+
|
21
|
+
# form the path of non enumerable diggable groups
|
22
|
+
path = path(path)
|
23
|
+
|
24
|
+
until path.empty? do
|
25
|
+
# *.* stands for "flatten the top level arrays until there's one * left
|
26
|
+
# which means iterate the fetcher with the following path over the result of the flattening"
|
27
|
+
while path.fetch(0) === '*' && path&.fetch(1, nil) === '*' do
|
28
|
+
data = data.flatten(1)
|
29
|
+
path.shift
|
30
|
+
end
|
31
|
+
|
32
|
+
# if the path ends with a "*" and that's it
|
33
|
+
return (block_given? ? yield(data) : data) if path.length === 1 && path.fetch(0) === '*'
|
34
|
+
|
35
|
+
subpath = path.shift
|
36
|
+
|
37
|
+
if subpath === '*'
|
38
|
+
subpath = path.shift
|
39
|
+
data = data&.collect {|node| fetch(data: node, path: subpath, strict: strict, default: default) }
|
40
|
+
else
|
41
|
+
data = fetch(data: data, path: subpath, strict: strict, default: default)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# return data or apply the custom block handler to the whole result
|
46
|
+
return (block_given? ? yield(data) : data)
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def fetch(data:, path:, strict:, default: nil)
|
52
|
+
path.reduce(data) { |node, key|
|
53
|
+
node != default ? (node&.fetch(key) { |key| strict ? (raise DigError) : default }) : node
|
54
|
+
}
|
55
|
+
rescue KeyError, TypeError, DigError => e
|
56
|
+
return default unless strict
|
57
|
+
|
58
|
+
line = "#{'-'*70}\n"
|
59
|
+
|
60
|
+
# ==== START ::: Intercept Awesome Print output =====
|
61
|
+
# TODO: Fix STDOUT interception with threads in mind!!!
|
62
|
+
str_io = StringIO.new
|
63
|
+
$stdout = str_io
|
64
|
+
|
65
|
+
ap data
|
66
|
+
ap_data = "#{line}#{$stdout.string}#{line}"
|
67
|
+
|
68
|
+
$stdout = STDOUT
|
69
|
+
# ==== END ::: Intercept Pretty Print output =====
|
70
|
+
|
71
|
+
raise DigError, "\nThere is no `#{path.join(' > ')}` path in some of the children:\n#{ap_data}"
|
72
|
+
end
|
73
|
+
|
74
|
+
def path(path)
|
75
|
+
path = path.try(:split, '*')
|
76
|
+
|
77
|
+
# split subgroups by "." and coerce types
|
78
|
+
path = path.collect do |dp|
|
79
|
+
dig_path = dp.try(:split, '.').compact.try(:map) do |p|
|
80
|
+
(p =~ /^[\d]+$/) ? p.to_i : p.to_sym
|
81
|
+
end
|
82
|
+
|
83
|
+
dig_path.reject! do |p|
|
84
|
+
p.try(:blank?)
|
85
|
+
end
|
86
|
+
|
87
|
+
dig_path.flatten
|
88
|
+
end
|
89
|
+
|
90
|
+
return path if path.length === 1
|
91
|
+
|
92
|
+
path = path.map {|e| e === [] ? ['*'] : [e, '*']}.flatten(1)
|
93
|
+
|
94
|
+
return path unless path.last === '*'
|
95
|
+
|
96
|
+
path
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
metadata
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hash_digger
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Serge Bedzhyk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-06-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.11'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.11'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: m
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.5'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.5'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest-reporters
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.3'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: byebug
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: letters
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: awesome_print
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.8'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.8'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: activesupport
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.0'
|
132
|
+
type: :runtime
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: ruby-try
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - "~>"
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '1.1'
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - "~>"
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '1.1'
|
153
|
+
description: A utilitarian lib to extract data from complex Hashes using String path
|
154
|
+
with recursions
|
155
|
+
email:
|
156
|
+
- smileart21@gmail.com
|
157
|
+
executables: []
|
158
|
+
extensions: []
|
159
|
+
extra_rdoc_files: []
|
160
|
+
files:
|
161
|
+
- ".gitignore"
|
162
|
+
- ".travis.yml"
|
163
|
+
- CODE_OF_CONDUCT.md
|
164
|
+
- Gemfile
|
165
|
+
- Gemfile.lock
|
166
|
+
- LICENSE.txt
|
167
|
+
- README.md
|
168
|
+
- Rakefile
|
169
|
+
- bin/console
|
170
|
+
- bin/setup
|
171
|
+
- hash_digger.gemspec
|
172
|
+
- lib/hash_digger.rb
|
173
|
+
- lib/hash_digger/version.rb
|
174
|
+
homepage: https://github.com/smileart/hash_digger
|
175
|
+
licenses:
|
176
|
+
- MIT
|
177
|
+
metadata:
|
178
|
+
allowed_push_host: https://rubygems.org
|
179
|
+
homepage_uri: https://github.com/smileart/hash_digger
|
180
|
+
source_code_uri: https://github.com/smileart/hash_digger
|
181
|
+
post_install_message:
|
182
|
+
rdoc_options: []
|
183
|
+
require_paths:
|
184
|
+
- lib
|
185
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
|
+
requirements:
|
187
|
+
- - ">="
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: '0'
|
190
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
191
|
+
requirements:
|
192
|
+
- - ">="
|
193
|
+
- !ruby/object:Gem::Version
|
194
|
+
version: '0'
|
195
|
+
requirements: []
|
196
|
+
rubyforge_project:
|
197
|
+
rubygems_version: 2.7.8
|
198
|
+
signing_key:
|
199
|
+
specification_version: 4
|
200
|
+
summary: Hash Digger (improved)
|
201
|
+
test_files: []
|