Class: Ferrum::Cookies::Cookie
- Inherits:
-
Object
- Object
- Ferrum::Cookies::Cookie
- Defined in:
- lib/ferrum/cookies/cookie.rb
Overview
Represents a [cookie value](chromedevtools.github.io/devtools-protocol/1-3/Network/#type-Cookie).
Instance Attribute Summary collapse
-
#attributes ⇒ Hash{String => [String, Boolean, nil]}
(also: #to_h)
readonly
The parsed JSON attributes.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
Compares different cookie objects.
-
#domain ⇒ String
The cookie’s domain.
-
#expires ⇒ Time?
Specifies when the cookie will expire.
-
#httponly? ⇒ Boolean
(also: #http_only?)
Specifies whether the cookie is HTTP-only or not.
-
#initialize(attributes) ⇒ Cookie
constructor
Initializes the cookie.
-
#name ⇒ String
The cookie’s name.
-
#path ⇒ String
The cookie’s path.
-
#priority ⇒ String
The priority of the cookie.
- #sameparty? ⇒ Boolean (also: #same_party?)
-
#samesite ⇒ "Strict", ...
(also: #same_site)
The ‘sameSite` configuration.
-
#secure? ⇒ Boolean
Specifies whether the cookie is secure or not.
-
#session? ⇒ Boolean
Specifies whether the cookie is a session cookie or not.
-
#size ⇒ Integer
The cookie’s size.
- #source_port ⇒ Integer
- #source_scheme ⇒ String
-
#to_s ⇒ String
Converts the cookie back into a raw cookie String.
-
#value ⇒ String
The cookie’s value.
Constructor Details
#initialize(attributes) ⇒ Cookie
Initializes the cookie.
20 21 22 |
# File 'lib/ferrum/cookies/cookie.rb', line 20 def initialize(attributes) @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Hash{String => [String, Boolean, nil]} (readonly) Also known as: to_h
The parsed JSON attributes.
12 13 14 |
# File 'lib/ferrum/cookies/cookie.rb', line 12 def attributes @attributes end |
Instance Method Details
#==(other) ⇒ Boolean
Compares different cookie objects.
153 154 155 |
# File 'lib/ferrum/cookies/cookie.rb', line 153 def ==(other) other.class == self.class && other.attributes == attributes end |
#domain ⇒ String
The cookie’s domain.
47 48 49 |
# File 'lib/ferrum/cookies/cookie.rb', line 47 def domain attributes["domain"] end |
#expires ⇒ Time?
Specifies when the cookie will expire.
112 113 114 |
# File 'lib/ferrum/cookies/cookie.rb', line 112 def expires Time.at(attributes["expires"]) if attributes["expires"].positive? end |
#httponly? ⇒ Boolean Also known as: http_only?
Specifies whether the cookie is HTTP-only or not.
93 94 95 |
# File 'lib/ferrum/cookies/cookie.rb', line 93 def httponly? attributes["httpOnly"] end |
#name ⇒ String
The cookie’s name.
29 30 31 |
# File 'lib/ferrum/cookies/cookie.rb', line 29 def name attributes["name"] end |
#path ⇒ String
The cookie’s path.
56 57 58 |
# File 'lib/ferrum/cookies/cookie.rb', line 56 def path attributes["path"] end |
#priority ⇒ String
The priority of the cookie.
121 122 123 |
# File 'lib/ferrum/cookies/cookie.rb', line 121 def priority @attributes["priority"] end |
#sameparty? ⇒ Boolean Also known as: same_party?
128 129 130 |
# File 'lib/ferrum/cookies/cookie.rb', line 128 def sameparty? @attributes["sameParty"] end |
#samesite ⇒ "Strict", ... Also known as: same_site
The ‘sameSite` configuration.
65 66 67 |
# File 'lib/ferrum/cookies/cookie.rb', line 65 def samesite attributes["sameSite"] end |
#secure? ⇒ Boolean
Specifies whether the cookie is secure or not.
84 85 86 |
# File 'lib/ferrum/cookies/cookie.rb', line 84 def secure? attributes["secure"] end |
#session? ⇒ Boolean
Specifies whether the cookie is a session cookie or not.
103 104 105 |
# File 'lib/ferrum/cookies/cookie.rb', line 103 def session? attributes["session"] end |
#size ⇒ Integer
The cookie’s size.
75 76 77 |
# File 'lib/ferrum/cookies/cookie.rb', line 75 def size attributes["size"] end |
#source_port ⇒ Integer
144 145 146 |
# File 'lib/ferrum/cookies/cookie.rb', line 144 def source_port @attributes["sourcePort"] end |
#source_scheme ⇒ String
137 138 139 |
# File 'lib/ferrum/cookies/cookie.rb', line 137 def source_scheme @attributes["sourceScheme"] end |
#to_s ⇒ String
Converts the cookie back into a raw cookie String.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'lib/ferrum/cookies/cookie.rb', line 163 def to_s string = String.new("#{@attributes['name']}=#{@attributes['value']}") @attributes.each do |key, value| case key when "name", "value" # no-op when "domain" then string << "; Domain=#{value}" when "path" then string << "; Path=#{value}" when "expires" then string << "; Expires=#{Time.at(value).httpdate}" when "httpOnly" then string << "; httpOnly" if value when "secure" then string << "; Secure" if value end end string end |
#value ⇒ String
The cookie’s value.
38 39 40 |
# File 'lib/ferrum/cookies/cookie.rb', line 38 def value attributes["value"] end |