hash-query 1.0.3 → 1.0.4

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.
@@ -115,11 +115,18 @@ module HashQuery
115
115
 
116
116
  def initialize(matcher)
117
117
  @key, @type = matcher.split(':')
118
- @type = Object.module_eval("::#{@type.capitalize}", __FILE__, __LINE__) if @type
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?(@type))
129
+ node.has_key?(@key) && (!@type || @type.any? { |type| node[@key].is_a?(type) })
123
130
  end
124
131
 
125
132
  def match!(node)
@@ -1,3 +1,3 @@
1
1
  module HashQuery
2
- VERSION = '1.0.3'
2
+ VERSION = '1.0.4'
3
3
  end
@@ -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.3
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-30 00:00:00.000000000 Z
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