module XRI
Public Class Methods
Source
# File lib/yadis/xrires.rb, line 71 def XRI.append_args(url, args) return url if args.length == 0 # rstrip question marks rstripped = url.dup while rstripped[-1].chr == '?' rstripped = rstripped[0...rstripped.length-1] end if rstripped.index('?') sep = '&' else sep = '?' end return url + sep + XRI.urlencode(args) end
Source
# File lib/yadis/xri.rb, line 30 def XRI.escape_for_iri(xri) esc = xri.dup # encode all % esc.gsub!(/%/, '%25') esc.gsub!(/\((.*?)\)/) { |xref_match| xref_match.gsub(/[\/\?\#]/) { |char_match| CGI::escape(char_match) } } return esc end
Note this is not not idempotent, so do not apply this more than once. XRI
Syntax section 2.3.2
Source
# File lib/yadis/xri.rb, line 10 def XRI.identifier_scheme(identifier) if identifier.match('^xri://') or XRI_AUTHORITIES.member?(identifier[0].chr) return :xri else return :uri end end
Source
# File lib/yadis/xri.rb, line 51 def XRI.iri_to_uri(iri) uri = iri.dup # for char in ucschar or iprivate # convert each char to %HH%HH%HH (as many %HH as octets) return uri end
RFC 3987 section 3.1
Source
# File lib/yadis/xri.rb, line 22 def XRI.to_iri_normal(xri) iri = xri.dup iri.insert(0, 'xri://') if not iri.match('^xri://') return escape_for_iri(iri) end
Transform an XRI
reference to an IRI reference. Note this is not not idempotent, so do not apply this to an identifier more than once. XRI
Syntax section 2.3.1
Source
Source
# File lib/yadis/xrires.rb, line 63 def XRI.urlencode(args) a = [] args.each do |key, val| a << (CGI::escape(key) + "=" + CGI::escape(val)) end a.join("&") end
Public Instance Methods
Source
# File lib/yadis/xri.rb, line 80 def make_xri(xri) if xri.index('xri://') != 0 xri = 'xri://' + xri end return xri end