better_dig 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 61055566fc7407f29bc2dfd61e80f1a43ec818726fd8b9fb8143519dbbe720fc
4
- data.tar.gz: d1ba361fd12f903bc63f24d02e036a18ba4a53d2cef7f987bcaa769eae37f212
2
+ SHA1:
3
+ metadata.gz: e24cd1db4400522310ec43dbfa379c1fff02eee2
4
+ data.tar.gz: ef9826d4bdca37b4a370a02658fe16971dfc8bf2
5
5
  SHA512:
6
- metadata.gz: 58a3fa77509621a49e857e4928871ad7c4eb0203cebdd0dd9c5f9c3e91529b0d8dd12a025683d3ef54f2a3cd002f0e9ca7d75f3a6e2ce8a543a7982afe7739dd
7
- data.tar.gz: 9f959be9d845dafd81aa7d31f86c741873fb8cce520dcd9f97a65a19e420781a947c677fe9b2b984bbed25d96d16568222b6c92071df823c6e1b52d01b386b1c
6
+ metadata.gz: 6a93d0aa1922dc1ed263c5458d174abd9eddc15a90e7e0239282f494f49cf008ccbd6ef5b5d1ba299c2551e1cf1f4aacd88430f8569ed3927027958e9ed31c6c
7
+ data.tar.gz: ce07c8ddc687bb282586b05e596d09174694052fe1395547303b9ceea7e5b2f79839d1684ef5502abedc1deaf460f3ec4f2a3429745c1e9d854443dac98c8ed5
data/.gitignore CHANGED
@@ -6,3 +6,5 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ *.gem
10
+ Gemfile.lock
data/README.md CHANGED
@@ -1,5 +1,4 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/better_dig.svg)](https://badge.fury.io/rb/better_dig)
2
- [![Downloads](https://img.shields.io/gem/dt/better_dig.svg)](https://rubygems.org/gems/better_dig)
3
2
  [![Maintainability](https://api.codeclimate.com/v1/badges/6bc69601493caa67e52e/maintainability)](https://codeclimate.com/github/berniechiu/better_dig/maintainability)
4
3
  [![Test Coverage](https://api.codeclimate.com/v1/badges/6bc69601493caa67e52e/test_coverage)](https://codeclimate.com/github/berniechiu/better_dig/test_coverage)
5
4
  [![Build Status](https://travis-ci.org/berniechiu/better_dig.svg?branch=master)](https://travis-ci.org/berniechiu/better_dig)
@@ -8,6 +7,8 @@
8
7
 
9
8
  Another kind of hash/array lookup you'll like
10
9
 
10
+ Supports dig-like method for Ruby below `2,3`
11
+
11
12
  ## Table of Context
12
13
 
13
14
  * [Installation](#installation)
@@ -36,7 +37,7 @@ Or install it yourself as:
36
37
  Basic Examples
37
38
 
38
39
  ```ruby
39
- hash = { hello: 'world', nested: { hello: 'world' }, nested_array: ['hello', 'world'] }
40
+ hash = { hello: 'world', nested: { hello: 'world' }, nested_array: ['hello', 'world'], is_cool: true }
40
41
 
41
42
  # Fetch by digg
42
43
  hash.digg(:hello) #=> 'world'
@@ -50,7 +51,8 @@ hash.digg(:hello, 0, :not_found) #=> nil
50
51
  hash.fetch_path('nested/hello') #=> 'world'
51
52
  hash.fetch_path('nested_array/0') #=> 'hello'
52
53
  hash.fetch_path('nested.hello', delimeter: '.') #=> 'hello'
53
- hash.fetch_path('nested/hello/none', default: 'zh-tw.not_found') # => 'zh-tw.not_found'
54
+ hash.fetch_path('nested/hello/none', default: 'zh-tw.not_found') #=> 'zh-tw.not_found'
55
+ hash.fetch_path('is_cool') #=> true
54
56
 
55
57
  # Since `nil` will be returned for not found value instead of TypeError if we are digging too far
56
58
  # we can use conditional block without breaking the application
@@ -1,3 +1,3 @@
1
1
  module BetterDig
2
- VERSION = "0.6.0"
2
+ VERSION = "0.7.0"
3
3
  end
data/lib/better_dig.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "better_dig/version"
2
3
 
3
4
  module BetterDig
@@ -13,7 +14,10 @@ module BetterDig
13
14
  end
14
15
 
15
16
  def fetch_path(path, default: nil, delimeter: '/')
16
- digg(*path.split(delimeter)) || default
17
+ digg(*path.split(delimeter)).tap do |value|
18
+ return default if value.nil?
19
+ return value
20
+ end
17
21
  end
18
22
 
19
23
  private
@@ -27,7 +31,10 @@ module BetterDig
27
31
  end
28
32
 
29
33
  def find_indifferent_value_by(key)
30
- self[key] || self[key.send(INDIFFERENT_FIND[key.class])]
34
+ self[key.freeze].tap do |value|
35
+ return value unless value.nil?
36
+ return self[key.send(INDIFFERENT_FIND[key.class])]
37
+ end
31
38
  end
32
39
  end
33
40
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: better_dig
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bernie Chiu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-03-17 00:00:00.000000000 Z
11
+ date: 2018-05-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -62,7 +62,6 @@ files:
62
62
  - ".gitignore"
63
63
  - ".travis.yml"
64
64
  - Gemfile
65
- - Gemfile.lock
66
65
  - LICENSE.txt
67
66
  - README.md
68
67
  - Rakefile
@@ -92,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
91
  version: '0'
93
92
  requirements: []
94
93
  rubyforge_project:
95
- rubygems_version: 2.7.6
94
+ rubygems_version: 2.6.14.1
96
95
  signing_key:
97
96
  specification_version: 4
98
97
  summary: Dig-like method for indifferent access of nested data lookup.
data/Gemfile.lock DELETED
@@ -1,30 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- better_dig (0.6.0)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- docile (1.1.5)
10
- json (2.1.0)
11
- minitest (5.11.3)
12
- rake (10.5.0)
13
- simplecov (0.15.1)
14
- docile (~> 1.1.0)
15
- json (>= 1.8, < 3)
16
- simplecov-html (~> 0.10.0)
17
- simplecov-html (0.10.2)
18
-
19
- PLATFORMS
20
- ruby
21
-
22
- DEPENDENCIES
23
- better_dig!
24
- bundler (~> 1.16)
25
- minitest (~> 5.0)
26
- rake (~> 10.0)
27
- simplecov (~> 0.15.1)
28
-
29
- BUNDLED WITH
30
- 1.16.1