class JsonReference::Reference
Attributes
pointer[RW]
uri[RW]
Public Class Methods
new(ref)
click to toggle source
# File lib/json_reference.rb, line 15 def initialize(ref) # Note that the #to_s of `nil` is an empty string. @uri = nil # given a simple fragment without '#', resolve as a JSON Pointer only as # per spec if ref.include?("#") uri, @pointer = ref.split('#') if uri && !uri.empty? @uri = URI.parse(uri) end @pointer ||= "" else @pointer = ref end # normalize pointers by prepending "#" and stripping trailing "/" @pointer = "#" + @pointer @pointer = @pointer.chomp("/") end
Public Instance Methods
<=>(other)
click to toggle source
# File lib/json_reference.rb, line 36 def <=>(other) to_s <=> other.to_s end
inspect()
click to toggle source
# File lib/json_reference.rb, line 40 def inspect "\#<JsonReference::Reference #{to_s}>" end
resolve_pointer(data)
click to toggle source
Given the document addressed by uri
, resolves the JSON Pointer part of the reference.
# File lib/json_reference.rb, line 46 def resolve_pointer(data) JsonPointer.evaluate(data, @pointer) end
to_s()
click to toggle source
# File lib/json_reference.rb, line 50 def to_s if @uri "#{@uri.to_s}#{@pointer}" else @pointer end end