powertools 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/maybe_chain.rb +27 -0
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ffbc936cb0b24ca1c6971392b36e29b9d964cece86ab3fbfa81b8679cf51210d
4
- data.tar.gz: 3b6068b56d74e329a161d9baaf47fce237152fcd117cf0f61c0c03b1582faef5
3
+ metadata.gz: 40eb8ed3218a255bb1e3f3cd1e883f5ef33eb4feaad5b953d93074d3a55ed067
4
+ data.tar.gz: 8a077bb13f7a3ced89d470664265600334cf6bb0f642f679701d79d74ddf7d3f
5
5
  SHA512:
6
- metadata.gz: 900bb0fa75ef4819b5c86e6657f24c9d425c81288361a0f5291d3af7947ab348021337a5666c6144274e91dd7b220d0c272315be7fd0d5905e39f62893ae2968
7
- data.tar.gz: 86d7e45d7fcd32a02bca5b225c56f9ec105465f0bdb28c51aef4035c251383460073a640c185851d30beeb6130a2397b04647bb79653be592fda545762341825
6
+ metadata.gz: ab8d7eccaae26072d8c328a4d282caebc5489518ff2655eb422dc767f9c2f1f982182ee4cddea0095fe23b2a7dca9b0210a5fcc6fd658dd2713461e19a16891e
7
+ data.tar.gz: b49a265e3f1c4cf745f80d9df8de4e0e950db6b4e171573eb36214384e924329909dc4f500e81289eef9894f54305fd590e7342cfc67177a0649eb985c2b3855
@@ -0,0 +1,27 @@
1
+ class Hash
2
+ def maybe_chain(args = [])
3
+ return nil unless self
4
+
5
+ r = self
6
+ args.each_with_index do |a, _i|
7
+ return nil if r[a].nil? || (r.class != Hash && r.class != Array)
8
+
9
+ r = a.instance_of?(Range) ? a.map { |i| r[i] } : r[a]
10
+ end
11
+ r
12
+ end
13
+ end
14
+
15
+ class Array
16
+ def maybe_chain(args = [])
17
+ return nil unless self
18
+
19
+ r = self
20
+ args.each_with_index do |a, _i|
21
+ return nil if r[a].nil? || (r.class != Hash && r.class != Array)
22
+
23
+ r = a.instance_of?(Range) ? a.map { |i| r[i] } : r[a]
24
+ end
25
+ r
26
+ end
27
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: powertools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - C. Kinniburgh
@@ -16,6 +16,7 @@ executables: []
16
16
  extensions: []
17
17
  extra_rdoc_files: []
18
18
  files:
19
+ - lib/maybe_chain.rb
19
20
  - lib/range.rb
20
21
  homepage: http://github.com/cjkinni/powertools
21
22
  licenses:
@@ -39,5 +40,5 @@ requirements: []
39
40
  rubygems_version: 3.2.22
40
41
  signing_key:
41
42
  specification_version: 4
42
- summary: A series of small improvements to Ruby classes
43
+ summary: A set of small improvements to Ruby classes
43
44
  test_files: []