lib/soaspec/exchange_handlers/response_extractor.rb in soaspec-0.2.16 vs lib/soaspec/exchange_handlers/response_extractor.rb in soaspec-0.2.17

- old
+ new

@@ -50,7 +50,33 @@ xpath = convert_to_pascal_case(xpath) if pascal_keys? xpath = '//' + xpath end xpath end + + # Convert snakecase to PascalCase + # @return [String] PascalCase converted path + def convert_to_pascal_case(key) + return key if /[[:upper:]]/ =~ key[0] # If first character already capital, don't do conversion + + key.split('_').map(&:capitalize).join + end + + # Find element with name specified or pascal case equivalent + # @return [String] String to find paths with pascal converted or given path + def add_pascal_path(json_path) + return json_path unless pascal_keys? + + json_path.split(',').collect do |sub_path| + "#{sub_path},#{convert_to_pascal_case(sub_path)}" + end.join(',') + end + + # @param [String] json_path Path set from Exchange + # @return [String] JSON Path + def prefix_json_path(json_path) + return json_path if json_path[0] == '$' + + "$..#{json_path}" + end end end