lib/jsonpath/parser.rb in jsonpath-0.8.3 vs lib/jsonpath/parser.rb in jsonpath-0.8.4
- old
+ new
@@ -20,11 +20,11 @@
end
ret
end
def parse_exp(exp)
- exp = exp.gsub(/@/, '').gsub(/[\(\)]/, '')
+ exp = exp.gsub(/@/, '').gsub(/[\(\)]/, '').gsub(/"/, '\'').strip
scanner = StringScanner.new(exp)
elements = []
until scanner.eos?
if scanner.scan(/\./)
sym = scanner.scan(/\w+/)
@@ -32,20 +32,21 @@
num = scanner.scan(/\d+/)
return @_current_node.send(sym.to_sym).send(op.to_sym, num.to_i)
end
if t = scanner.scan(/\['\w+'\]+/)
elements << t.gsub(/\[|\]|'|\s+/, '')
- elsif t = scanner.scan(/\s+[<>=][<>=]?\s+?/)
+ elsif t = scanner.scan(/(\s+)?[<>=][<>=]?(\s+)?/)
operator = t
- elsif t = scanner.scan(/(\s+)?'?(\w+)?[.,]?(\w+)?'?(\s+)?/) # @TODO: At this point I should trim somewhere...
+ elsif t = scanner.scan(/(\s+)?'?.*'?(\s+)?/)
operand = t.delete("'").strip
elsif t = scanner.scan(/.*/)
raise "Could not process symbol: #{t}"
end
end
el = dig(elements, @_current_node)
return false unless el
return true if operator.nil? && el
+
operand = operand.to_f if operand.to_i.to_s == operand || operand.to_f.to_s == operand
el.send(operator.strip, operand)
end
private