hash-query 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/hash_query.rb +9 -2
- data/lib/hash_query/version.rb +1 -1
- data/test/test_hash_query.rb +8 -0
- metadata +2 -2
data/lib/hash_query.rb
CHANGED
@@ -115,11 +115,18 @@ module HashQuery
|
|
115
115
|
|
116
116
|
def initialize(matcher)
|
117
117
|
@key, @type = matcher.split(':')
|
118
|
-
|
118
|
+
if @type
|
119
|
+
@type = case @type
|
120
|
+
when 'boolean'
|
121
|
+
[FalseClass, TrueClass]
|
122
|
+
else
|
123
|
+
[Object.module_eval("::#{@type.capitalize}", __FILE__, __LINE__)]
|
124
|
+
end
|
125
|
+
end
|
119
126
|
end
|
120
127
|
|
121
128
|
def match?(node)
|
122
|
-
node.has_key?(@key) && (!@type || node[@key].is_a?(
|
129
|
+
node.has_key?(@key) && (!@type || @type.any? { |type| node[@key].is_a?(type) })
|
123
130
|
end
|
124
131
|
|
125
132
|
def match!(node)
|
data/lib/hash_query/version.rb
CHANGED
data/test/test_hash_query.rb
CHANGED
@@ -134,4 +134,12 @@ class TestHquery_value < MiniTest::Unit::TestCase
|
|
134
134
|
assert_equal 3, hash.query_value('b')
|
135
135
|
end
|
136
136
|
|
137
|
+
def test_boolean_match
|
138
|
+
hash = { 'a' => true, 'b' => false, 'c' => 'true' }
|
139
|
+
|
140
|
+
assert_equal true, hash.query_value('a:boolean')
|
141
|
+
assert_equal false, hash.query_value('b:boolean')
|
142
|
+
assert_equal nil, hash.query_value('c:boolean')
|
143
|
+
end
|
144
|
+
|
137
145
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hash-query
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-31 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Provides a css-like selector system for querying values out of deeply
|
15
15
|
nested hashes
|