queryable_hash 0.0.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/queryable_hash/version.rb +1 -1
- data/lib/queryable_hash/wrapper.rb +3 -5
- data/test/wrapper_test.rb +20 -20
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0bca97eac6efb1840781a53a7abc1418daa5952
|
4
|
+
data.tar.gz: dd5de78c9ec422b080e61159ed5ac1d3c9187f57
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3f45ee135f6cd853a71f82e2c28186c4ad1176f44643b85d9afdc5ba25416c78de503a9b8551c06151ca3f81de1fe4f42d4119494bf137661a8e40a5019c7d50
|
7
|
+
data.tar.gz: 0b0c9175454f3cc25f05000a02cf9d5b76c29fc722f566f4801b48fe62a545cdd13ed883684ba5874da40f3c54b4063f7b17cbe14b192645eca301866069bf07
|
@@ -11,7 +11,7 @@ module QueryableHash
|
|
11
11
|
super hash
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def get_all(*queries, nil_value: nil)
|
15
15
|
queries.reduce([]) do |memo, query|
|
16
16
|
context = self
|
17
17
|
query.split(".").each do |name|
|
@@ -22,11 +22,11 @@ module QueryableHash
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
def
|
25
|
+
def get(*queries, nil_value: nil, raise_when_nil: nil)
|
26
26
|
nil_value = @nil_value if nil_value.nil?
|
27
27
|
raise_when_nil = @raise_when_nil if raise_when_nil.nil?
|
28
28
|
|
29
|
-
first =
|
29
|
+
first = get_all(*queries, nil_value: nil_value).find do |result|
|
30
30
|
result != nil_value
|
31
31
|
end
|
32
32
|
first ||= nil_value
|
@@ -35,8 +35,6 @@ module QueryableHash
|
|
35
35
|
first
|
36
36
|
end
|
37
37
|
|
38
|
-
alias_method :find, :find_first
|
39
|
-
|
40
38
|
def to_hash
|
41
39
|
@original_hash
|
42
40
|
end
|
data/test/wrapper_test.rb
CHANGED
@@ -28,13 +28,13 @@ module QueryableHash
|
|
28
28
|
@queryable = QueryableHash.wrap(@data)
|
29
29
|
end
|
30
30
|
|
31
|
-
test "
|
31
|
+
test "get_all" do
|
32
32
|
query = "glossary.gloss_div.gloss_list.gloss_entry.id"
|
33
|
-
assert @queryable.
|
33
|
+
assert @queryable.get_all(query) == ["SGML"]
|
34
34
|
end
|
35
35
|
|
36
|
-
test "
|
37
|
-
title, term, para = @queryable.
|
36
|
+
test "get_all with multiple queries" do
|
37
|
+
title, term, para = @queryable.get_all(
|
38
38
|
"glossary.title",
|
39
39
|
"glossary.gloss_div.gloss_list.gloss_entry.gloss_term",
|
40
40
|
"glossary.gloss_div.gloss_list.gloss_entry.gloss_def.para"
|
@@ -44,13 +44,13 @@ module QueryableHash
|
|
44
44
|
assert para == "A meta-markup language, used to create markup languages such as DocBook."
|
45
45
|
end
|
46
46
|
|
47
|
-
test "
|
47
|
+
test "get" do
|
48
48
|
query = "glossary.gloss_div.gloss_list.gloss_entry.id"
|
49
|
-
assert @queryable.
|
49
|
+
assert @queryable.get(query) == "SGML"
|
50
50
|
end
|
51
51
|
|
52
|
-
test "
|
53
|
-
result = @queryable.
|
52
|
+
test "get with multiple queries" do
|
53
|
+
result = @queryable.get(
|
54
54
|
"glossary.title",
|
55
55
|
"glossary.gloss_div.gloss_list.gloss_entry.gloss_term",
|
56
56
|
"glossary.gloss_div.gloss_list.gloss_entry.gloss_def.para"
|
@@ -58,24 +58,24 @@ module QueryableHash
|
|
58
58
|
assert result == "example glossary"
|
59
59
|
end
|
60
60
|
|
61
|
-
test "
|
61
|
+
test "get with missing key" do
|
62
62
|
query = "this.key.does.not.exist"
|
63
|
-
assert @queryable.
|
63
|
+
assert @queryable.get(query).nil?
|
64
64
|
end
|
65
65
|
|
66
|
-
test "
|
66
|
+
test "get with missing key and nil_value" do
|
67
67
|
query = "nate.this.key.does.not.exist"
|
68
|
-
assert @queryable.
|
68
|
+
assert @queryable.get(query, nil_value: "missing") == "missing"
|
69
69
|
end
|
70
70
|
|
71
|
-
test "
|
71
|
+
test "get with missing key and nil_value set by instance" do
|
72
72
|
query = "nate.this.key.does.not.exist"
|
73
73
|
queryable = QueryableHash.wrap(@data, nil_value: "missing")
|
74
|
-
assert queryable.
|
74
|
+
assert queryable.get(query) == "missing"
|
75
75
|
end
|
76
76
|
|
77
|
-
test "
|
78
|
-
term = @queryable.
|
77
|
+
test "get with multiple queries some invalid" do
|
78
|
+
term = @queryable.get(
|
79
79
|
"glossary.div.list.entry.term",
|
80
80
|
"glossary.gloss_div.list.entry.term",
|
81
81
|
"glossary.gloss_div.gloss_list.entry.term",
|
@@ -85,21 +85,21 @@ module QueryableHash
|
|
85
85
|
assert term == "Standard Generalized Markup Language"
|
86
86
|
end
|
87
87
|
|
88
|
-
test "
|
88
|
+
test "get with raise_when_nil" do
|
89
89
|
query = "nate.this.key.does.not.exist"
|
90
90
|
begin
|
91
|
-
@queryable.
|
91
|
+
@queryable.get(query, raise_when_nil: true)
|
92
92
|
rescue NotFoundError => e
|
93
93
|
end
|
94
94
|
|
95
95
|
assert e
|
96
96
|
end
|
97
97
|
|
98
|
-
test "
|
98
|
+
test "get with raise_when_nil set by instance" do
|
99
99
|
query = "nate.this.key.does.not.exist"
|
100
100
|
begin
|
101
101
|
queryable = QueryableHash.wrap(@data, raise_when_nil: true)
|
102
|
-
queryable.
|
102
|
+
queryable.get(query)
|
103
103
|
rescue NotFoundError => e
|
104
104
|
end
|
105
105
|
assert e
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: queryable_hash
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
-
description:
|
83
|
+
description:
|
84
84
|
email:
|
85
85
|
- natehop@gmail.com
|
86
86
|
executables: []
|
@@ -113,11 +113,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.4.5
|
116
|
+
rubygems_version: 2.4.5.1
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
|
-
summary:
|
119
|
+
summary: Find data in Hashes using dot notation queries
|
120
120
|
test_files:
|
121
121
|
- test/test_helper.rb
|
122
122
|
- test/wrapper_test.rb
|
123
|
-
has_rdoc:
|