@@ -10,6 +10,13 @@ module URL
1010 # Represents an absolute URL with scheme and/or authority.
1111 # Examples: "https://example.com/path", "//cdn.example.com/lib.js", "http://localhost/"
1212 class Absolute < Relative
13+ # Initialize a new absolute URL.
14+ #
15+ # @parameter scheme [String] The URL scheme (e.g., "https", "http").
16+ # @parameter authority [String] The authority component (e.g., "example.com", "user@host:port").
17+ # @parameter path [String] The path component (defaults to "/").
18+ # @parameter query [String, nil] The query string.
19+ # @parameter fragment [String, nil] The fragment identifier.
1320 def initialize ( scheme , authority , path = "/" , query = nil , fragment = nil )
1421 @scheme = scheme
1522 @authority = authority
@@ -18,18 +25,25 @@ def initialize(scheme, authority, path = "/", query = nil, fragment = nil)
1825 super ( path , query , fragment )
1926 end
2027
28+ # @attribute [String] The URL scheme.
2129 attr :scheme
30+
31+ # @attribute [String] The authority component.
2232 attr :authority
2333
34+ # Check if the URL has a non-empty scheme.
35+ #
36+ # @returns [Boolean] True if a scheme is present and non-empty.
2437 def scheme?
2538 @scheme and !@scheme . empty?
2639 end
2740
41+ # Check if the URL has a non-empty authority.
42+ #
43+ # @returns [Boolean] True if an authority is present and non-empty.
2844 def authority?
2945 @authority and !@authority . empty?
30- end
31-
32- # Combine this absolute URL with a relative reference according to RFC 3986 Section 5.
46+ end # Combine this absolute URL with a relative reference according to RFC 3986 Section 5.
3347 #
3448 # @parameter other [String, Relative, Reference, Absolute] The reference to resolve.
3549 # @returns [Absolute, String] The resolved absolute URL.
@@ -118,14 +132,24 @@ def with(scheme: @scheme, authority: @authority, path: nil, query: @query, fragm
118132 self . class . new ( scheme , authority , Path . expand ( @path , path , pop ) , query , fragment )
119133 end
120134
135+ # Convert the URL to an array representation.
136+ #
137+ # @returns [Array] An array of `[scheme, authority, path, query, fragment]`.
121138 def to_ary
122139 [ @scheme , @authority , @path , @query , @fragment ]
123140 end
124141
142+ # Compare this URL with another for sorting purposes.
143+ #
144+ # @parameter other [Absolute] The URL to compare with.
145+ # @returns [Integer] -1, 0, or 1 based on component-wise comparison.
125146 def <=>( other )
126147 to_ary <=> other . to_ary
127148 end
128149
150+ # Convert the URL to its string representation.
151+ #
152+ # @returns [String] The formatted absolute URL string.
129153 def to_s
130154 append
131155 end
0 commit comments