Sha256: debc1c41beac2ef0f8fea18b9486ed12bc316911d71f0360c73aa1b22a7cd89d
Contents?: true
Size: 1.66 KB
Versions: 21
Compression:
Stored size: 1.66 KB
Contents
require 'strscan' # Ripped with appreciation from Joshua Hull's useful JsonPath gem # https://github.com/joshbuddy/jsonpath/blob/792ff9a928998f4252692cd3c1ba378ed931a5aa/lib/jsonpath.rb # Only including the code that Pact needs, to reduce dependencies and potential gem version clashes. module Pact module MatchingRules class JsonPath attr_reader :path def initialize(path) scanner = StringScanner.new(path) @path = [] bracket_count = 0 while not scanner.eos? if token = scanner.scan(/\$/) @path << token elsif token = scanner.scan(/@/) @path << token elsif token = scanner.scan(/[:a-zA-Z0-9_-]+/) @path << "['#{token}']" elsif token = scanner.scan(/'(.*?)'/) @path << "[#{token}]" elsif token = scanner.scan(/\[/) count = 1 while !count.zero? if t = scanner.scan(/\[/) token << t count += 1 elsif t = scanner.scan(/\]/) token << t count -= 1 elsif t = scanner.scan(/[^\[\]]*/) token << t end end @path << token elsif token = scanner.scan(/\.\./) @path << token elsif scanner.scan(/\./) nil elsif token = scanner.scan(/\*/) @path << token elsif token = scanner.scan(/[><=] \d+/) @path.last << token elsif token = scanner.scan(/./) @path.last << token end end def to_s path.join end end end end end
Version data entries
21 entries across 21 versions & 1 rubygems