hash-pipe 0.0.2 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ddb4c5e25772c8e591f435f87d0eb18187cb9ae6
4
- data.tar.gz: 5c09a00a7c8efaf8ade75d6e66dd6815d1fc6a4f
3
+ metadata.gz: 0c23ebd04fd2a64e16045d5b42f8b39c606a5f59
4
+ data.tar.gz: 69519dcdf75138afdc7d2291b28c0297e31d4f46
5
5
  SHA512:
6
- metadata.gz: 9350e08d5df889ef833c5cab43c5e4cae0c92124a6e4dfcc041c7d307d5dd07c280c9df6fef1779d854e750ae9d0106c4050e13697f7747e656df0e1a8951156
7
- data.tar.gz: 0b1c90b6c209a715217761aa5272e356fd39428bd2be60774bb67b91e0c3ce2c413e97b4b2e344d04ec34690ebf39e7e0b8aea1b4b91c7aed23ce54dd096b6e2
6
+ metadata.gz: a4d85d61874cd686a61ed0a770697e97be378a20cf75e3af61bd4c7d9dc8325b2d184097f4aedb8335a0f1c2da605f2416171ec984b264ad03fbe38c32449d4f
7
+ data.tar.gz: c17f32ded2be8f0a5e6824d46a21b561c1378151e2cf7a8a316fa0fa4e1975d8beb51c838716833d5d063143d4a00b41a37c4ce745d44a1f6b14ddd71ca09a57
data/Gemfile.lock CHANGED
@@ -1,24 +1,24 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hash-pipe (0.0.2)
4
+ hash-pipe (0.1.0)
5
5
  activesupport (~> 4.1)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
- activesupport (4.1.0)
11
- i18n (~> 0.6, >= 0.6.9)
10
+ activesupport (4.2.0)
11
+ i18n (~> 0.7)
12
12
  json (~> 1.7, >= 1.7.7)
13
13
  minitest (~> 5.1)
14
- thread_safe (~> 0.1)
14
+ thread_safe (~> 0.3, >= 0.3.4)
15
15
  tzinfo (~> 1.1)
16
16
  coderay (1.1.0)
17
17
  diff-lcs (1.2.5)
18
- i18n (0.6.9)
19
- json (1.8.1)
18
+ i18n (0.7.0)
19
+ json (1.8.2)
20
20
  method_source (0.8.2)
21
- minitest (5.3.3)
21
+ minitest (5.5.1)
22
22
  pry (0.9.12.6)
23
23
  coderay (~> 1.0)
24
24
  method_source (~> 0.8)
@@ -32,8 +32,8 @@ GEM
32
32
  diff-lcs (>= 1.1.3, < 2.0)
33
33
  rspec-mocks (2.14.4)
34
34
  slop (3.4.7)
35
- thread_safe (0.3.3)
36
- tzinfo (1.1.0)
35
+ thread_safe (0.3.4)
36
+ tzinfo (1.2.2)
37
37
  thread_safe (~> 0.1)
38
38
 
39
39
  PLATFORMS
data/hash-pipe.gemspec CHANGED
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "hash-pipe"
5
- s.version = "0.0.2"
5
+ s.version = "0.1.0"
6
6
  s.authors = ["Damien Timewell"]
7
7
  s.email = ["mail@damientimewell.com"]
8
8
  s.licenses = ['MIT']
data/lib/hash-pipe.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'active_support/core_ext'
2
2
 
3
3
  require 'hash_pipe/key_conversion'
4
- require 'hash_pipe/value_checks'
4
+ require 'hash_pipe/value_checks'
5
+ require 'hash_pipe/nested_values'
@@ -0,0 +1,21 @@
1
+ Hash.class_eval do
2
+
3
+ def nested_fetch(path)
4
+ path = Array(path)
5
+
6
+ value = self
7
+ until path.empty?
8
+ value = value[path.shift]
9
+ end
10
+
11
+ value
12
+ end
13
+
14
+ def nested_delete(path)
15
+ path = Array(path)
16
+ last_path_element = path.pop
17
+
18
+ self.nested_fetch(path).delete last_path_element
19
+ end
20
+
21
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'nested_keys' do
4
+
5
+ it 'should work for flat hashes' do
6
+ hash = { 'bank_code' => 123 }
7
+
8
+ hash.nested_fetch('bank_code').should eq 123
9
+ end
10
+
11
+ it 'should be able to find nested values' do
12
+ hash = { 'bank' => { 'code' => 123, 'number' => 12345 } }
13
+ hash.nested_fetch(['bank', 'code']).should eq 123
14
+ end
15
+
16
+ it 'should be able to find nested values of mixed symbols and string keys' do
17
+ hash = { 'bank' => { code: { 'SE' => 1 }, name: 'SEB' } }
18
+
19
+ hash.nested_fetch(['bank', :code, 'SE']).should eq 1
20
+ hash.nested_fetch(['bank', :name]).should eq 'SEB'
21
+ end
22
+
23
+ it 'should be able to delete nested values' do
24
+ hash = { 'bank' => { code: { 'SE' => 1 }, name: 'SEB' }, 'email' => 'email@example.com' }
25
+ hash.nested_delete ['bank', :name]
26
+
27
+ hash['bank'][:name].should be_nil
28
+ end
29
+
30
+ it 'should be able to delete root values' do
31
+ hash = { 'email' => 'email@example.com' }
32
+ hash.nested_delete 'email'
33
+ hash['email'].should be_nil
34
+ end
35
+
36
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash-pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien Timewell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-28 00:00:00.000000000 Z
11
+ date: 2015-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -68,8 +68,10 @@ files:
68
68
  - hash-pipe.gemspec
69
69
  - lib/hash-pipe.rb
70
70
  - lib/hash_pipe/key_conversion.rb
71
+ - lib/hash_pipe/nested_values.rb
71
72
  - lib/hash_pipe/value_checks.rb
72
73
  - spec/hash-pipe/key_conversion_spec.rb
74
+ - spec/hash-pipe/nested_keys_spec.rb
73
75
  - spec/hash-pipe/value_checks_spec.rb
74
76
  - spec/spec_helper.rb
75
77
  homepage: https://github.com/idlefingers/hash-pipe
@@ -98,6 +100,7 @@ specification_version: 4
98
100
  summary: A small collection of useful hash extensions
99
101
  test_files:
100
102
  - spec/hash-pipe/key_conversion_spec.rb
103
+ - spec/hash-pipe/nested_keys_spec.rb
101
104
  - spec/hash-pipe/value_checks_spec.rb
102
105
  - spec/spec_helper.rb
103
106
  has_rdoc: