queryable_hash 0.0.4 → 1.0.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: 013d8d8d053748011b04843c3fc884acc1add3a5
4
- data.tar.gz: c7ae4a613c552ab8b5e0ae8980f0296ee6882397
3
+ metadata.gz: c0bca97eac6efb1840781a53a7abc1418daa5952
4
+ data.tar.gz: dd5de78c9ec422b080e61159ed5ac1d3c9187f57
5
5
  SHA512:
6
- metadata.gz: c77d43636a7b286f7a6031447df3253919c81e283740cbb8edf93dc41f3e38cf52a8e2c09d26d184876355a9da56d68c036e0850ef1c15c426c380f56cffc11a
7
- data.tar.gz: 028abca755d539225757554fe8de48b634e2d9b36ad728bc0177ba242a14159a734d66f445435cf891a5a89da23c37dadce5cc937ea9ee16adb926601eb83d91
6
+ metadata.gz: 3f45ee135f6cd853a71f82e2c28186c4ad1176f44643b85d9afdc5ba25416c78de503a9b8551c06151ca3f81de1fe4f42d4119494bf137661a8e40a5019c7d50
7
+ data.tar.gz: 0b0c9175454f3cc25f05000a02cf9d5b76c29fc722f566f4801b48fe62a545cdd13ed883684ba5874da40f3c54b4063f7b17cbe14b192645eca301866069bf07
@@ -1,3 +1,3 @@
1
1
  module QueryableHash
2
- VERSION = "0.0.4"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -11,7 +11,7 @@ module QueryableHash
11
11
  super hash
12
12
  end
13
13
 
14
- def find_all(*queries, nil_value: nil)
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 find_first(*queries, nil_value: nil, raise_when_nil: nil)
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 = find_all(*queries, nil_value: nil_value).find do |result|
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
@@ -28,13 +28,13 @@ module QueryableHash
28
28
  @queryable = QueryableHash.wrap(@data)
29
29
  end
30
30
 
31
- test "find_all" do
31
+ test "get_all" do
32
32
  query = "glossary.gloss_div.gloss_list.gloss_entry.id"
33
- assert @queryable.find_all(query) == ["SGML"]
33
+ assert @queryable.get_all(query) == ["SGML"]
34
34
  end
35
35
 
36
- test "find_all with multiple queries" do
37
- title, term, para = @queryable.find_all(
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 "find_first" do
47
+ test "get" do
48
48
  query = "glossary.gloss_div.gloss_list.gloss_entry.id"
49
- assert @queryable.find_first(query) == "SGML"
49
+ assert @queryable.get(query) == "SGML"
50
50
  end
51
51
 
52
- test "find_first with multiple queries" do
53
- result = @queryable.find_first(
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 "find_first with missing key" do
61
+ test "get with missing key" do
62
62
  query = "this.key.does.not.exist"
63
- assert @queryable.find_first(query).nil?
63
+ assert @queryable.get(query).nil?
64
64
  end
65
65
 
66
- test "find_first with missing key and nil_value" do
66
+ test "get with missing key and nil_value" do
67
67
  query = "nate.this.key.does.not.exist"
68
- assert @queryable.find_first(query, nil_value: "missing") == "missing"
68
+ assert @queryable.get(query, nil_value: "missing") == "missing"
69
69
  end
70
70
 
71
- test "find_first with missing key and nil_value set by instance" do
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.find_first(query) == "missing"
74
+ assert queryable.get(query) == "missing"
75
75
  end
76
76
 
77
- test "find_first with multiple queries some invalid" do
78
- term = @queryable.find_first(
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 "find_first with raise_when_nil" do
88
+ test "get with raise_when_nil" do
89
89
  query = "nate.this.key.does.not.exist"
90
90
  begin
91
- @queryable.find_first(query, raise_when_nil: true)
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 "find_first with raise_when_nil set by instance" do
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.find_first(query)
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
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: 2015-03-02 00:00:00.000000000 Z
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: Safely & easily find data in Hashes using dot notation queries.
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: Safely & easily find data in Hashes using dot notation queries.
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: