@@ -19,25 +19,34 @@ def self.parse(path = "/", parameters = nil)
1919 self . new ( path , query , fragment , parameters )
2020 end
2121
22+ # Initialize the reference.
23+ #
24+ # @parameter path [String] The path component, e.g. `/foo/bar/index.html`.
25+ # @parameter query [String | Nil] The un-parsed query string, e.g. 'x=10&y=20'.
26+ # @parameter fragment [String | Nil] The fragment, the part after the '#'.
27+ # @parameter parameters [Hash | Nil] User supplied parameters that will be appended to the query part.
2228 def initialize ( path = "/" , query = nil , fragment = nil , parameters = nil )
2329 @path = path
2430 @query = query
2531 @fragment = fragment
2632 @parameters = parameters
2733 end
2834
29- # The path component, e.g. /foo/bar/index.html
35+ # @attribute [String] The path component, e.g. ` /foo/bar/index.html`.
3036 attr_accessor :path
3137
32- # The un-parsed query string, e.g. 'x=10&y=20'
38+ # @attribute [String] The un-parsed query string, e.g. 'x=10&y=20'.
3339 attr_accessor :query
3440
35- # A fragment, the part after the '#'
41+ # @attribute [String] The fragment, the part after the '#'.
3642 attr_accessor :fragment
3743
38- # User supplied parameters that will be appended to the query part.
44+ # @attribute [Hash] User supplied parameters that will be appended to the query part.
3945 attr_accessor :parameters
4046
47+ # Freeze the reference.
48+ #
49+ # @returns [Reference] The frozen reference.
4150 def freeze
4251 return self if frozen?
4352
@@ -49,14 +58,25 @@ def freeze
4958 super
5059 end
5160
61+ # Implicit conversion to an array.
62+ #
63+ # @returns [Array] The reference as an array, `[path, query, fragment, parameters]`.
5264 def to_ary
5365 [ @path , @query , @fragment , @parameters ]
5466 end
5567
68+ # Compare two references.
69+ #
70+ # @parameter other [Reference] The other reference to compare.
71+ # @returns [Integer] -1, 0, 1 if the reference is less than, equal to, or greater than the other reference.
5672 def <=> other
5773 to_ary <=> other . to_ary
5874 end
5975
76+ # Type-cast a reference.
77+ #
78+ # @parameter reference [Reference, String] The reference to type-cast.
79+ # @returns [Reference] The type-casted reference.
6080 def self . [] reference
6181 if reference . is_a? self
6282 return reference
@@ -65,19 +85,23 @@ def self.[] reference
6585 end
6686 end
6787
88+ # @returns [Boolean] Whether the reference has parameters.
6889 def parameters?
6990 @parameters and !@parameters . empty?
7091 end
7192
93+ # @returns [Boolean] Whether the reference has a query string.
7294 def query?
7395 @query and !@query . empty?
7496 end
7597
98+ # @returns [Boolean] Whether the reference has a fragment.
7699 def fragment?
77100 @fragment and !@fragment . empty?
78101 end
79102
80- def append ( buffer )
103+ # Append the reference to the given buffer.
104+ def append ( buffer = String . new )
81105 if query?
82106 buffer << URL . escape_path ( @path ) << "?" << @query
83107 buffer << "&" << URL . encode ( @parameters ) if parameters?
@@ -93,8 +117,11 @@ def append(buffer)
93117 return buffer
94118 end
95119
120+ # Convert the reference to a string, e.g. `/foo/bar/index.html?x=10&y=20#section`
121+ #
122+ # @returns [String] The reference as a string.
96123 def to_s
97- append ( String . new )
124+ append
98125 end
99126
100127 # Merges two references as specified by RFC2396, similar to `URI.join`.
0 commit comments