Class: Pact::MatchingRules::JsonPath
- Inherits:
-
Object
- Object
- Pact::MatchingRules::JsonPath
- Defined in:
- lib/pact/matching_rules/jsonpath.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path) ⇒ JsonPath
constructor
A new instance of JsonPath.
- #to_s ⇒ Object
Constructor Details
#initialize(path) ⇒ JsonPath
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pact/matching_rules/jsonpath.rb', line 13 def initialize(path) scanner = StringScanner.new(path) @path = [] 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 end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/pact/matching_rules/jsonpath.rb', line 11 def path @path end |
Instance Method Details
#to_s ⇒ Object
53 54 55 |
# File 'lib/pact/matching_rules/jsonpath.rb', line 53 def to_s path.join end |