sjain-hash_keep 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ === 1.0.0 / 2009-01-09
2
+
3
+ * 1 major enhancement
4
+
5
+ * Birthday!
6
+
@@ -0,0 +1,6 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/hash_keep.rb
6
+ test/test_hash_keep.rb
@@ -0,0 +1,54 @@
1
+ = hash_keep
2
+
3
+ * http://www.pathf.com/blogs/author/sharad-jain
4
+
5
+ == DESCRIPTION:
6
+
7
+ Adds 'keep' method to Hash class
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ In order to filter out unwanted keys from a Hash, what we normally do is:
12
+
13
+ Hash.reject { |k,v| !keys_to_keep.include?(k) }
14
+
15
+ A more DSL way to do this would be:
16
+
17
+ Hash.keep(keys_to_keep)
18
+
19
+ == SYNOPSIS:
20
+
21
+ This gem adds the 'keep' method to Hash
22
+
23
+ == REQUIREMENTS:
24
+
25
+ * TODO
26
+
27
+ == INSTALL:
28
+
29
+ * TODO
30
+
31
+ == LICENSE:
32
+
33
+ (The MIT License)
34
+
35
+ Copyright (c) 2009 Sharad Jain, Pathfinder Associates, LLC.
36
+
37
+ Permission is hereby granted, free of charge, to any person obtaining
38
+ a copy of this software and associated documentation files (the
39
+ 'Software'), to deal in the Software without restriction, including
40
+ without limitation the rights to use, copy, modify, merge, publish,
41
+ distribute, sublicense, and/or sell copies of the Software, and to
42
+ permit persons to whom the Software is furnished to do so, subject to
43
+ the following conditions:
44
+
45
+ The above copyright notice and this permission notice shall be
46
+ included in all copies or substantial portions of the Software.
47
+
48
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
49
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
50
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
51
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
52
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
53
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
54
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/hash_keep'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('hash_keep', HashKeep::VERSION) do |p|
7
+ p.developer('Pathfinder Associates, LLC.', 'info@pathf.com')
8
+ p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
9
+ p.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
10
+ p.rubyforge_name = p.name # TODO this is default value
11
+ # p.extra_deps = [
12
+ # ['activerecord', ">= 2.1.0"]
13
+ # ]
14
+ # p.extra_dev_deps = [
15
+ # ['newgem', ">= #{::Newgem::VERSION}"],
16
+ # ]
17
+
18
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
19
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
20
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
21
+ p.rsync_args = '-av --delete --ignore-errors'
22
+ end
23
+
24
+ require 'newgem/tasks' # load /tasks/*.rake
25
+ Dir['tasks/**/*.rake'].each { |t| load t }
26
+
27
+ # TODO - want other tests/tasks run by default? Add them to the list
28
+ # task :default => [:spec, :features]
@@ -0,0 +1,9 @@
1
+ class Hash
2
+ def keep(keys_to_keep)
3
+ reject { |k,v| !keys_to_keep.include?(k) }
4
+ end
5
+ end
6
+
7
+ class HashKeep
8
+ VERSION = '1.0.0'
9
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestNaturalKey < Test::Unit::TestCase
4
+ def test_keep
5
+ assert_equal({:b=>"b", :c=>"c"}, {:a => "a", :b => "b", :c => "c", :d => "d"}.keep([:b,:c,:e]))
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/hash_keep'
3
+
4
+ # gem install redgreen for colored test output
5
+ begin require 'redgreen'; rescue LoadError; end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sjain-hash_keep
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Pathfinder Associates, LLC.
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-01-09 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.8.0
23
+ version:
24
+ description: Adds 'keep' method to Hash class
25
+ email:
26
+ - info@pathf.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - Manifest.txt
38
+ - README.txt
39
+ - Rakefile
40
+ - lib/hash_keep.rb
41
+ - test/test_hash_keep.rb
42
+ - test/test_helper.rb
43
+ has_rdoc: true
44
+ homepage: http://www.pathf.com/blogs/author/sharad-jain
45
+ post_install_message: PostInstall.txt
46
+ rdoc_options:
47
+ - --main
48
+ - README.txt
49
+ require_paths:
50
+ - lib
51
+ required_ruby_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ requirements: []
64
+
65
+ rubyforge_project: hash_keep
66
+ rubygems_version: 1.2.0
67
+ signing_key:
68
+ specification_version: 2
69
+ summary: Adds 'keep' method to Hash class
70
+ test_files:
71
+ - test/test_hash_keep.rb
72
+ - test/test_helper.rb