lib/jsonpath/parser.rb in jsonpath-0.8.10 vs lib/jsonpath/parser.rb in jsonpath-0.8.11
- old
+ new
@@ -1,6 +1,7 @@
require 'strscan'
+require 'to_regexp'
class JsonPath
# Parser parses and evaluates an expression passed to @_current_node.
class Parser
def initialize(node)
@@ -32,13 +33,15 @@
num = scanner.scan(/\d+/)
return @_current_node.send(sym.to_sym).send(op.to_sym, num.to_i)
end
if t = scanner.scan(/\['[a-zA-Z@&\*\/\$%\^\?_]+'\]+/)
elements << t.gsub(/\[|\]|'|\s+/, '')
- elsif t = scanner.scan(/(\s+)?[<>=][<>=]?(\s+)?/)
+ elsif t = scanner.scan(/(\s+)?[<>=][=~]?(\s+)?/)
operator = t
elsif t = scanner.scan(/(\s+)?'?.*'?(\s+)?/)
- operand = t.delete("'").strip
+ operand = operator.strip == "=~" ? t.to_regexp : t.delete("'").strip
+ elsif t = scanner.scan(/\/\w+\//)
+
elsif t = scanner.scan(/.*/)
raise "Could not process symbol: #{t}"
end
end
el = dig(elements, @_current_node)