Skip to content

Commit 7ff4fb3

Browse files
[DOC] Enhanced RDoc for common methods (#50)
1 parent 02dfc79 commit 7ff4fb3

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

lib/uri/common.rb

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,23 +185,13 @@ def self.parse(uri)
185185
RFC3986_PARSER.parse(uri)
186186
end
187187

188+
# Merges the given URI strings +str+
189+
# per {RFC 2396}[https://www.rfc-editor.org/rfc/rfc2396.html].
188190
#
189-
# == Synopsis
190-
#
191-
# URI::join(str[, str, ...])
192-
#
193-
# == Args
194-
#
195-
# +str+::
196-
# String(s) to work with, will be converted to RFC3986 URIs before merging.
197-
#
198-
# == Description
191+
# Each string in +str+ is converted to an
192+
# {RFC3986 URI}[https://www.rfc-editor.org/rfc/rfc3986.html] before being merged.
199193
#
200-
# Joins URIs.
201-
#
202-
# == Usage
203-
#
204-
# require 'uri'
194+
# Examples:
205195
#
206196
# URI.join("http://example.com/","main.rbx")
207197
# # => #<URI::HTTP http://example.com/main.rbx>
@@ -246,7 +236,7 @@ def self.join(*str)
246236
# URI.extract("text here http://foo.example.org/bla and here mailto:test@example.com and here also.")
247237
# # => ["http://foo.example.com/bla", "mailto:test@example.com"]
248238
#
249-
def self.extract(str, schemes = nil, &block)
239+
def self.extract(str, schemes = nil, &block) # :nodoc:
250240
warn "URI.extract is obsolete", uplevel: 1 if $VERBOSE
251241
DEFAULT_PARSER.extract(str, schemes, &block)
252242
end
@@ -283,7 +273,7 @@ def self.extract(str, schemes = nil, &block)
283273
# p $&
284274
# end
285275
#
286-
def self.regexp(schemes = nil)
276+
def self.regexp(schemes = nil)# :nodoc:
287277
warn "URI.regexp is obsolete", uplevel: 1 if $VERBOSE
288278
DEFAULT_PARSER.make_regexp(schemes)
289279
end
@@ -340,16 +330,38 @@ def self.regexp(schemes = nil)
340330
# and then to encoding +enc+.
341331
#
342332
# In either case, the returned string has forced encoding Encoding::US_ASCII.
343-
#
344333
def self.encode_www_form_component(str, enc=nil)
345334
_encode_uri_component(/[^*\-.0-9A-Z_a-z]/, TBLENCWWWCOMP_, str, enc)
346335
end
347336

348-
# Decodes given +str+ of URL-encoded form data.
337+
# Returns a string decoded from the given \URL-encoded string +str+.
338+
#
339+
# The given string is first encoded as Encoding::ASCII-8BIT (using String#b),
340+
# then decoded (as below), and finally force-encoded to the given encoding +enc+.
341+
#
342+
# The returned string:
343+
#
344+
# - Preserves:
345+
#
346+
# - Characters <tt>'*'</tt>, <tt>'.'</tt>, <tt>'-'</tt>, and <tt>'_'</tt>.
347+
# - Character in ranges <tt>'a'..'z'</tt>, <tt>'A'..'Z'</tt>,
348+
# and <tt>'0'..'9'</tt>.
349+
#
350+
# Example:
351+
#
352+
# URI.decode_www_form_component('*.-_azAZ09')
353+
# # => "*.-_azAZ09"
354+
#
355+
# - Converts:
356+
#
357+
# - Character <tt>'+'</tt> to character <tt>' '</tt>.
358+
# - Each "percent notation" to an ASCII character.
359+
#
360+
# Example:
349361
#
350-
# This decodes + to SP.
362+
# URI.decode_www_form_component('Here+are+some+punctuation+characters%3A+%2C%3B%3F%3A')
363+
# # => "Here are some punctuation characters: ,;?:"
351364
#
352-
# See URI.encode_www_form_component, URI.decode_www_form.
353365
def self.decode_www_form_component(str, enc=Encoding::UTF_8)
354366
_decode_uri_component(/\+|%\h\h/, str, enc)
355367
end

0 commit comments

Comments
 (0)