Sha256: 4406d076f350b51484ad29e62466ea5c52ab456c0037200c90e7ce1749eca374
Contents?: true
Size: 834 Bytes
Versions: 27
Compression:
Stored size: 834 Bytes
Contents
module OasParser class Pointer def initialize(raw_pointer) @raw_pointer = raw_pointer end def resolve(document) return document if escaped_pointer == "" tokens.reduce(document) do |nested_doc, token| nested_doc.fetch(token) end end private def escaped_pointer if @raw_pointer.start_with?("#") Addressable::URI.unencode(@raw_pointer[1..-1]) else @raw_pointer end end def parse_token(token) if token =~ /\A\d+\z/ token.to_i else token.gsub("~0", "~").gsub("~1", "/") end end def tokens tokens = escaped_pointer[1..-1].split("/") if @raw_pointer.end_with?("/") tokens << "" end tokens.map do |token| parse_token(token) end end end end
Version data entries
27 entries across 27 versions & 1 rubygems