[ruby/uri] [DOC] Enhanced RDoc for common methods

(https://github.com/ruby/uri/pull/50)

https://github.com/ruby/uri/commit/7ff4fb372b
This commit is contained in:
Burdette Lamar 2023-01-06 08:20:31 -06:00 committed by git
parent cee5beab1d
commit ddbf7be94d

View File

@ -185,23 +185,13 @@ module URI
RFC3986_PARSER.parse(uri)
end
# Merges the given URI strings +str+
# per {RFC 2396}[https://www.rfc-editor.org/rfc/rfc2396.html].
#
# == Synopsis
# Each string in +str+ is converted to an
# {RFC3986 URI}[https://www.rfc-editor.org/rfc/rfc3986.html] before being merged.
#
# URI::join(str[, str, ...])
#
# == Args
#
# +str+::
# String(s) to work with, will be converted to RFC3986 URIs before merging.
#
# == Description
#
# Joins URIs.
#
# == Usage
#
# require 'uri'
# Examples:
#
# URI.join("http://example.com/","main.rbx")
# # => #<URI::HTTP http://example.com/main.rbx>
@ -246,7 +236,7 @@ module URI
# URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.")
# # => ["http://foo.example.com/bla", "mailto:test@example.com"]
#
def self.extract(str, schemes = nil, &block)
def self.extract(str, schemes = nil, &block) # :nodoc:
warn "URI.extract is obsolete", uplevel: 1 if $VERBOSE
DEFAULT_PARSER.extract(str, schemes, &block)
end
@ -283,7 +273,7 @@ module URI
# p $&
# end
#
def self.regexp(schemes = nil)
def self.regexp(schemes = nil)# :nodoc:
warn "URI.regexp is obsolete", uplevel: 1 if $VERBOSE
DEFAULT_PARSER.make_regexp(schemes)
end
@ -340,16 +330,38 @@ module URI
# and then to encoding +enc+.
#
# In either case, the returned string has forced encoding Encoding::US_ASCII.
#
def self.encode_www_form_component(str, enc=nil)
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_, str, enc)
end
# Decodes given +str+ of URL-encoded form data.
# Returns a string decoded from the given \URL-encoded string +str+.
#
# This decodes + to SP.
# The given string is first encoded as Encoding::ASCII-8BIT (using String#b),
# then decoded (as below), and finally force-encoded to the given encoding +enc+.
#
# The returned string:
#
# - Preserves:
#
# - Characters <tt>'*'</tt>, <tt>'.'</tt>, <tt>'-'</tt>, and <tt>'_'</tt>.
# - Character in ranges <tt>'a'..'z'</tt>, <tt>'A'..'Z'</tt>,
# and <tt>'0'..'9'</tt>.
#
# Example:
#
# URI.decode_www_form_component('*.-_azAZ09')
# # => "*.-_azAZ09"
#
# - Converts:
#
# - Character <tt>'+'</tt> to character <tt>' '</tt>.
# - Each "percent notation" to an ASCII character.
#
# Example:
#
# URI.decode_www_form_component('Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A')
# # => "Here are some punctuation characters: ,;?:"
#
# See URI.encode_www_form_component, URI.decode_www_form.
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
_decode_uri_component(/\+|%\h\h/, str, enc)
end