From aee926572f1baa61012be34e1d1ea6c55fe13c3c Mon Sep 17 00:00:00 2001 From: vigneshdurairaj Date: Sat, 27 Jun 2020 17:51:58 +0530 Subject: [PATCH 1/2] Changes to allow spaced values infilter_expression_parser --- lib/hpath/parser/filter_expression_parser.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hpath/parser/filter_expression_parser.rb b/lib/hpath/parser/filter_expression_parser.rb index e75ddd3..c460221 100644 --- a/lib/hpath/parser/filter_expression_parser.rb +++ b/lib/hpath/parser/filter_expression_parser.rb @@ -28,7 +28,7 @@ def parse(string) current_filter = Hpath::Filter.new parent = {} # look up table - string.gsub(/\s/, "").each_char do |char| + string.each_char do |char| unless special_character?(char) char_buffer << char else From c67e96f1bf1dc7039b2bf481eb3e3a9007990c0c Mon Sep 17 00:00:00 2001 From: vigneshdurairaj Date: Sat, 27 Jun 2020 21:13:32 +0530 Subject: [PATCH 2/2] Adding Inequality feature --- lib/hpath/filter.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/hpath/filter.rb b/lib/hpath/filter.rb index 6592b89..4803ef4 100644 --- a/lib/hpath/filter.rb +++ b/lib/hpath/filter.rb @@ -10,6 +10,7 @@ def initialize(string = nil) [:and, []] else case string + when /!=/ then [:inequality, string.split("!=")] when /=/ then [:equality, string.split("=")] when // then [:greater_than, string.split(">")] @@ -41,6 +42,13 @@ def applies?(object) elsif object.respond_to(key) object.send(key) == value end + elsif @type == :inequality + key, value = @operands + if object.is_a?(Hash) + object[key.to_s] != value.to_s + elsif object.respond_to(key) + object.send(key) != value + end end end end