better_dig 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +28 -8
- data/lib/better_dig.rb +4 -0
- data/lib/better_dig/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61055566fc7407f29bc2dfd61e80f1a43ec818726fd8b9fb8143519dbbe720fc
|
4
|
+
data.tar.gz: d1ba361fd12f903bc63f24d02e036a18ba4a53d2cef7f987bcaa769eae37f212
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58a3fa77509621a49e857e4928871ad7c4eb0203cebdd0dd9c5f9c3e91529b0d8dd12a025683d3ef54f2a3cd002f0e9ca7d75f3a6e2ce8a543a7982afe7739dd
|
7
|
+
data.tar.gz: 9f959be9d845dafd81aa7d31f86c741873fb8cce520dcd9f97a65a19e420781a947c677fe9b2b984bbed25d96d16568222b6c92071df823c6e1b52d01b386b1c
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
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)
|
2
3
|
[![Maintainability](https://api.codeclimate.com/v1/badges/6bc69601493caa67e52e/maintainability)](https://codeclimate.com/github/berniechiu/better_dig/maintainability)
|
3
4
|
[![Test Coverage](https://api.codeclimate.com/v1/badges/6bc69601493caa67e52e/test_coverage)](https://codeclimate.com/github/berniechiu/better_dig/test_coverage)
|
4
5
|
[![Build Status](https://travis-ci.org/berniechiu/better_dig.svg?branch=master)](https://travis-ci.org/berniechiu/better_dig)
|
@@ -32,24 +33,43 @@ Or install it yourself as:
|
|
32
33
|
|
33
34
|
## Usage
|
34
35
|
|
36
|
+
Basic Examples
|
37
|
+
|
35
38
|
```ruby
|
36
39
|
hash = { hello: 'world', nested: { hello: 'world' }, nested_array: ['hello', 'world'] }
|
37
40
|
|
38
|
-
|
39
|
-
hash.digg(
|
40
|
-
hash.digg('
|
41
|
-
hash.digg('
|
41
|
+
# Fetch by digg
|
42
|
+
hash.digg(:hello) #=> 'world'
|
43
|
+
hash.digg('hello') #=> 'world'
|
44
|
+
hash.digg('nested', 'hello') #=> 'world'
|
45
|
+
hash.digg('nested_array', 0) #=> 'hello'
|
46
|
+
hash.digg('nested_array', '0') #=> 'hello'
|
47
|
+
hash.digg(:hello, 0, :not_found) #=> nil
|
48
|
+
|
49
|
+
# Fetch by path
|
50
|
+
hash.fetch_path('nested/hello') #=> 'world'
|
51
|
+
hash.fetch_path('nested_array/0') #=> 'hello'
|
52
|
+
hash.fetch_path('nested.hello', delimeter: '.') #=> 'hello'
|
53
|
+
hash.fetch_path('nested/hello/none', default: 'zh-tw.not_found') # => 'zh-tw.not_found'
|
42
54
|
|
43
|
-
# Since `nil` will be returned for not found value instead of
|
44
|
-
# we can use conditional block
|
55
|
+
# Since `nil` will be returned for not found value instead of TypeError if we are digging too far
|
56
|
+
# we can use conditional block without breaking the application
|
45
57
|
|
46
58
|
if hash.digg(:nested, :hello, :world) # => nil
|
47
|
-
# DO SOMETHING
|
59
|
+
# DO SOMETHING WHEN FOUND
|
48
60
|
else
|
49
|
-
# DO SOMETHING
|
61
|
+
# DO SOMETHING WHEN NOT FOUND
|
50
62
|
end
|
51
63
|
```
|
52
64
|
|
65
|
+
Or probably in the Rails views
|
66
|
+
|
67
|
+
```erb
|
68
|
+
<%= object.hash_data.digg(:snapshot, :price) %>
|
69
|
+
|
70
|
+
```
|
71
|
+
|
72
|
+
|
53
73
|
## Contributing
|
54
74
|
|
55
75
|
Bug reports and pull requests are welcome on GitHub at https://github.com/berniechiu/better_dig.
|
data/lib/better_dig.rb
CHANGED
data/lib/better_dig/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.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-
|
11
|
+
date: 2018-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|