Class: Ferrum::Cookies::Cookie

Inherits:
Object
  • Object
show all
Defined in:
lib/ferrum/cookies/cookie.rb

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Cookie

Initializes the cookie.

Parameters:

  • attributes (Hash{String => String})

    The parsed JSON attributes.



20
21
22
# File 'lib/ferrum/cookies/cookie.rb', line 20

def initialize(attributes)
  @attributes = attributes
end

Instance Attribute Details

#attributesHash{String => [String, Boolean, nil]} (readonly) Also known as: to_h

The parsed JSON attributes.

Returns:

  • (Hash{String => [String, Boolean, nil]})


12
13
14
# File 'lib/ferrum/cookies/cookie.rb', line 12

def attributes
  @attributes
end

Instance Method Details

#==(other) ⇒ Boolean

Compares different cookie objects.

Returns:

  • (Boolean)


153
154
155
# File 'lib/ferrum/cookies/cookie.rb', line 153

def ==(other)
  other.class == self.class && other.attributes == attributes
end

#domainString

The cookie’s domain.

Returns:

  • (String)


47
48
49
# File 'lib/ferrum/cookies/cookie.rb', line 47

def domain
  attributes["domain"]
end

#expiresTime?

Specifies when the cookie will expire.

Returns:

  • (Time, nil)


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.

Returns:

  • (Boolean)


93
94
95
# File 'lib/ferrum/cookies/cookie.rb', line 93

def httponly?
  attributes["httpOnly"]
end

#nameString

The cookie’s name.

Returns:

  • (String)


29
30
31
# File 'lib/ferrum/cookies/cookie.rb', line 29

def name
  attributes["name"]
end

#pathString

The cookie’s path.

Returns:

  • (String)


56
57
58
# File 'lib/ferrum/cookies/cookie.rb', line 56

def path
  attributes["path"]
end

#priorityString

The priority of the cookie.

Returns:

  • (String)


121
122
123
# File 'lib/ferrum/cookies/cookie.rb', line 121

def priority
  @attributes["priority"]
end

#sameparty?Boolean Also known as: same_party?

Returns:

  • (Boolean)


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.

Returns:

  • ("Strict", "Lax", "None", nil)


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.

Returns:

  • (Boolean)


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.

Returns:

  • (Boolean)


103
104
105
# File 'lib/ferrum/cookies/cookie.rb', line 103

def session?
  attributes["session"]
end

#sizeInteger

The cookie’s size.

Returns:

  • (Integer)


75
76
77
# File 'lib/ferrum/cookies/cookie.rb', line 75

def size
  attributes["size"]
end

#source_portInteger

Returns:

  • (Integer)


144
145
146
# File 'lib/ferrum/cookies/cookie.rb', line 144

def source_port
  @attributes["sourcePort"]
end

#source_schemeString

Returns:

  • (String)


137
138
139
# File 'lib/ferrum/cookies/cookie.rb', line 137

def source_scheme
  @attributes["sourceScheme"]
end

#to_sString

Converts the cookie back into a raw cookie String.

Returns:

  • (String)

    The 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

#valueString

The cookie’s value.

Returns:

  • (String)


38
39
40
# File 'lib/ferrum/cookies/cookie.rb', line 38

def value
  attributes["value"]
end