hash_selectors 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6f465f6bc5e31b99b2176ff434d1f9cff6a1f7a6
4
+ data.tar.gz: 148130fcfc88301609302815eb212e9648010c83
5
+ SHA512:
6
+ metadata.gz: 7c70c25c510e5f0dde0cfee605a23f5cd733d8438d91235d9d9bbf14f31a631d9819be0cd0068113e7f694218feba63ff9cf462fd57562e55858a4970e7cf5d7
7
+ data.tar.gz: a35bcaf8270fe29a219322e88144b391681488ceee3927dc21343fa4a14af0e34d1642e19002626ac8fcc051818ef8d5e04732bc1022beda0b73ad8a3ea4e816
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Kevin C. Baird
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,4 @@
1
+ hash-selectors
2
+ ==============
3
+
4
+ A small set of select methods for Ruby Hashes
@@ -0,0 +1,25 @@
1
+ # Provides additional select methods for Hashes.
2
+ # Automatically mixed-in to Hash on load.
3
+ module HashSelectors
4
+
5
+ # @example
6
+ # {a: 1, b: 2, c: 3}.select_by_keys :a, :b # returns {a: 1, b: 2}
7
+ #
8
+ # @param [Glob of any type] ks
9
+ # @return [Hash] That subset of the Hash whose keys are included within the *ks* argument.
10
+ def select_by_keys(*ks)
11
+ select { |k,v| ks.include?(k) }
12
+ end
13
+
14
+ # @example
15
+ # {a: 1, b: 2, c: 3}.select_by_values 2, 3 # returns {b: 2, c: 3}
16
+ #
17
+ # @param [Glob of any type] vs
18
+ # @return [Hash] That subset of the Hash whose values are included within the *vs* argument.
19
+ def select_by_values(*vs)
20
+ select { |k,v| vs.include?(v) }
21
+ end
22
+
23
+ Hash.include(self)
24
+
25
+ end
@@ -0,0 +1,38 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+ require 'hash_selectors'
3
+
4
+ RSpec.describe HashSelectors do
5
+
6
+ describe "Constants"
7
+
8
+ ### INSTANCE METHODS
9
+
10
+ describe "#select_by_keys" do
11
+ context "assuming a Hash: {a: 1, b: 2, c: {c2: [:d, :e]}}" do
12
+ let(:the_hash) { {a: 1, b: 2, c: {c2: [:d, :e]}} }
13
+ context "and given :a, :d" do
14
+ subject { the_hash.select_by_keys :a, :d }
15
+ it { is_expected.to eq({a: 1}) }
16
+ end
17
+ context "and given :a, :b" do
18
+ subject { the_hash.select_by_keys :a, :b }
19
+ it { is_expected.to eq({a: 1, b: 2}) }
20
+ end
21
+ context "and given :b, :c" do
22
+ subject { the_hash.select_by_keys :b, :c }
23
+ it { is_expected.to eq({b: 2, c: {c2: [:d, :e]}}) }
24
+ end
25
+ end
26
+ end
27
+
28
+ describe "#select_by_values" do
29
+ context "assuming a Hash: {a: 1, b: 2, c: {c2: [:d, :e]}}" do
30
+ let(:the_hash) { {a: 1, b: 2, c: {c2: [:d, :e]}} }
31
+ context "and given 1, 2" do
32
+ subject { the_hash.select_by_values 1, 2 }
33
+ it { is_expected.to eq({a: 1, b: 2}) }
34
+ end
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,9 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_filter 'spec'
6
+ add_group 'Libraries', 'lib'
7
+ end
8
+
9
+
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hash_selectors
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kevin C. Baird
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-06-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: simplecov
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.8'
41
+ description: Provides additional select-type methods for Ruby Hashes
42
+ email: kcbaird@world.oberlin.edu
43
+ executables: []
44
+ extensions: []
45
+ extra_rdoc_files: []
46
+ files:
47
+ - LICENSE
48
+ - README.md
49
+ - lib/hash_selectors.rb
50
+ - spec/hash_selectors_spec.rb
51
+ - spec/spec_helper.rb
52
+ homepage: https://github.com/kbaird/hash-selectors
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ requirements:
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ requirements: []
71
+ rubyforge_project:
72
+ rubygems_version: 2.2.2
73
+ signing_key:
74
+ specification_version: 4
75
+ summary: Some select methods for Ruby Hashes
76
+ test_files: []
77
+ has_rdoc: yard