hash_reject_recursively 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40bb74bde1b148e59b7d6971a9bff4cf9cd3d1ca
4
+ data.tar.gz: 227b2c75d469953b4fc1a945f2b342c859426029
5
+ SHA512:
6
+ metadata.gz: 35af86655639dd5cdc77c7fda110e77b913742a67ba014ab4022149ed5c6a0c1462e0f35963bfcfe4b062186d72d31db22069debdffcc8d5943528054b384844
7
+ data.tar.gz: c046d6baf9b444af97fd02cb6b146cd5f26cd0e9cf0841d2f71b9393fd08d0892a47db7028ab1913949b1e4e4fd474447a5a46b86dec00e30c1c8412fe8ed9ca
@@ -0,0 +1 @@
1
+ repo_token: Yg1EktUTYnPl6cc19VPR5z48d3q4IYcAo
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ ruby "2.3.1"
4
+
5
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Rafael Biriba
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.
@@ -0,0 +1,63 @@
1
+ # Hash Reject Recursively
2
+
3
+ Like Hash#reject but recursively.
4
+
5
+ Deletes recursively every key-value pair from hash for which block evaluates to true.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'hash_reject_recursively'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install hash_reject_recursively
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ languages = {
27
+ ruby: { lines: 100 },
28
+ python: { lines: nil },
29
+ java: { lines: nil },
30
+ php: nil
31
+ }
32
+
33
+ new_hash = languages.deep_reject { |key, value| value.nil? }
34
+ # new_hash == { ruby: { lines: 100 }, python: {}, java: {} }
35
+
36
+ new_hash = languages.deep_reject { |key, value| value.blank? } # Rails example
37
+ # new_hash == { ruby: { lines: 100 } }
38
+
39
+ languages.deep_reject! { |key, value| value.nil? }
40
+ # languages == { ruby: { lines: 100 }, python: {}, java: {} }
41
+
42
+ ```
43
+
44
+ Note 1: `deep_reject!` changes the original object
45
+
46
+ Note 2: `.blank?` in example above it's [Rails implementation method](http://apidock.com/rails/Object/blank%3F).
47
+
48
+
49
+ ## License
50
+
51
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
52
+
53
+ ## Contributing
54
+
55
+ First of all, **thank you** for wanting to help!
56
+
57
+ 1. [Fork it](https://help.github.com/articles/fork-a-repo).
58
+ 2. Create a feature branch - `git checkout -b more_magic`
59
+ 3. Add tests and make your changes
60
+ 4. Check if tests are ok - `rake spec`
61
+ 5. Commit changes - `git commit -am "Added more magic"`
62
+ 6. Push to Github - `git push origin more_magic`
63
+ 7. Send a [pull request](https://help.github.com/articles/using-pull-requests)! :heart:
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hash_reject_recursively/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hash_reject_recursively"
8
+ spec.version = HashRejectRecursively::VERSION
9
+ spec.authors = ["Rafael Biriba"]
10
+ spec.email = ["biribarj@gmail.com"]
11
+
12
+ spec.summary = "Like Hash#reject but recursively"
13
+ spec.description = "Deletes recursively every key-value pair from hash for which block evaluates to true."
14
+ spec.homepage = "https://github.com/rafaelbiriba/hash_reject_recursively"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.13"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "rspec", "~> 3.0"
26
+ spec.add_development_dependency "byebug"
27
+ spec.add_development_dependency "coveralls"
28
+ end
@@ -0,0 +1,2 @@
1
+ require "hash_reject_recursively/version"
2
+ require "hash_reject_recursively/hash"
@@ -0,0 +1,12 @@
1
+ class Hash
2
+ def deep_reject(&blk)
3
+ self.dup.deep_reject!(&blk)
4
+ end
5
+
6
+ def deep_reject!(&blk)
7
+ self.each do |k, v|
8
+ v.deep_reject!(&blk) if v.is_a?(Hash)
9
+ self.delete(k) if blk.call(k, v)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ module HashRejectRecursively
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash_reject_recursively
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Rafael Biriba
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-23 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.13'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.13'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: coveralls
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Deletes recursively every key-value pair from hash for which block evaluates
84
+ to true.
85
+ email:
86
+ - biribarj@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".coveralls.yml"
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - hash_deep_reject.gemspec
99
+ - lib/hash_reject_recursively.rb
100
+ - lib/hash_reject_recursively/hash.rb
101
+ - lib/hash_reject_recursively/version.rb
102
+ homepage: https://github.com/rafaelbiriba/hash_reject_recursively
103
+ licenses:
104
+ - MIT
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.5.1
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Like Hash#reject but recursively
126
+ test_files: []