Skip to content

Commit 437268a

Browse files
committed
Improved documentation for Protocol::HTTP::Cookie.
1 parent 78ddfc7 commit 437268a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

lib/protocol/http/cookie.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,39 @@ module Protocol
1010
module HTTP
1111
# Represents an individual cookie key-value pair.
1212
class Cookie
13+
# Initialize the cookie with the given name, value, and directives.
14+
#
15+
# @parameter name [String] The name of the cookiel, e.g. "session_id".
16+
# @parameter value [String] The value of the cookie, e.g. "1234".
17+
# @parameter directives [Hash] The directives of the cookie, e.g. `{"path" => "/"}`.
1318
def initialize(name, value, directives)
1419
@name = name
1520
@value = value
1621
@directives = directives
1722
end
1823

24+
# @attribute [String] The name of the cookie.
1925
attr :name
26+
27+
# @attribute [String] The value of the cookie.
2028
attr :value
29+
30+
# @attribute [Hash] The directives of the cookie.
2131
attr :directives
2232

33+
# Encode the name of the cookie.
2334
def encoded_name
2435
URL.escape(@name)
2536
end
2637

38+
# Encode the value of the cookie.
2739
def encoded_value
2840
URL.escape(@value)
2941
end
3042

43+
# Convert the cookie to a string.
44+
#
45+
# @returns [String] The string representation of the cookie.
3146
def to_s
3247
buffer = String.new.b
3348

@@ -49,6 +64,10 @@ def to_s
4964
return buffer
5065
end
5166

67+
# Parse a string into a cookie.
68+
#
69+
# @parameter string [String] The string to parse.
70+
# @returns [Cookie] The parsed cookie.
5271
def self.parse(string)
5372
head, *directives = string.split(/\s*;\s*/)
5473

@@ -62,6 +81,10 @@ def self.parse(string)
6281
)
6382
end
6483

84+
# Parse a list of strings into a hash of directives.
85+
#
86+
# @parameter strings [Array(String)] The list of strings to parse.
87+
# @returns [Hash] The hash of directives.
6588
def self.parse_directives(strings)
6689
strings.collect do |string|
6790
key, value = string.split("=", 2)

0 commit comments

Comments
 (0)